Skip to content

Commit

Permalink
Add type-safetyness to Fix type
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Mar 4, 2024
1 parent 12495e5 commit bb8590c
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions code/lib/cli/src/automigrate/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ export interface RunOptions<ResultType> {
*/
export type Prompt = 'auto' | 'manual' | 'notification';

export interface Fix<ResultType = any> {
type BaseFix<ResultType = any> = {
id: string;
promptType?: Prompt | ((result: ResultType) => Promise<Prompt> | Prompt);
/**
* The from/to version range of Storybook that this fix applies to. The strings are semver ranges.
* The versionRange will only be checked if the automigration is part of an upgrade.
Expand All @@ -38,8 +37,23 @@ export interface Fix<ResultType = any> {
versionRange: [from: string, to: string];
check: (options: CheckOptions) => Promise<ResultType | null>;
prompt: (result: ResultType) => string;
run?: (options: RunOptions<ResultType>) => Promise<void>;
}
};

type PromptType<ResultType = any, T = Prompt> =
| T
| ((result: ResultType) => Promise<Prompt> | Prompt);

export type Fix<ResultType = any> = (
| {
promptType?: PromptType<ResultType, 'auto'>;
run: (options: RunOptions<ResultType>) => Promise<void>;
}
| {
promptType: PromptType<ResultType, 'manual' | 'notification'>;
run?: never;
}
) &
BaseFix<ResultType>;

export type FixId = string;

Expand Down

0 comments on commit bb8590c

Please sign in to comment.