Skip to content

Commit

Permalink
fix: update types for test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Parkreiner committed Sep 20, 2024
1 parent a6f1405 commit f852190
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ export interface CoderScriptAttributes {
url: string;
}

export type ResourceInstance<T extends string = string> =
T extends "coder_script" ? CoderScriptAttributes : Record<string, string>;

/**
* finds the first instance of the given resource type in the given state. If
* name is specified, it will only find the instance with the given name.
Expand All @@ -123,10 +126,7 @@ export const findResourceInstance = <T extends string>(
state: TerraformState,
type: T,
name?: string,
// if type is "coder_script" return CoderScriptAttributes
): T extends "coder_script"
? CoderScriptAttributes
: Record<string, string> => {
): ResourceInstance<T> => {
const resource = state.resources.find(
(resource) =>
resource.type === type && (name ? resource.name === name : true),
Expand All @@ -139,7 +139,8 @@ export const findResourceInstance = <T extends string>(
`Resource ${type} has ${resource.instances.length} instances`,
);
}
return resource.instances[0].attributes as any;

return resource.instances[0].attributes as ResourceInstance<T>;
};

/**
Expand Down

0 comments on commit f852190

Please sign in to comment.