Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PromptOptions union type does not work well in TypeScript 3.8.x #263

Open
IngvarKofoed opened this issue Mar 4, 2020 · 0 comments · May be fixed by #307
Open

PromptOptions union type does not work well in TypeScript 3.8.x #263

IngvarKofoed opened this issue Mar 4, 2020 · 0 comments · May be fixed by #307

Comments

@IngvarKofoed
Copy link

The following code

const { doSomething } = await prompt<{ doSomething: 'Yes' | 'No' }>({
  type: 'autocomplete',
  name: 'doSomething',
  message: 'Some Message',
  choices: ['Yes', 'No'],
  initial: 'Yes'
});

Gives the following compile error:

Argument of type '{ type: string; name: string; message: string; choices: string[]; initial: string; }' is not assignable to parameter of type 'ArrayPromptOptions | BasePromptOptions | BooleanPromptOptions | StringPromptOptions | ... 4 more ... | (ArrayPromptOptions | ... 6 more ... | ((this: Enquirer<...>) => PromptOptions))[]'.
  Object literal may only specify known properties, and 'choices' does not exist in type 'BasePromptOptions'.ts(2345)

The problem is the type property on BasePromptOptions. This breaks the union type PromptOptions so that the compiler does not see that type as the discriminant.

Versions:
enquirer: 2.3.2
typescript: 3.8.3
node: 12.12.0
yarn: 1.22.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant