You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, first of all, thanks for enquirer 👍 Nice library!
Currently, enquirer has a return type of Promise<object>:
import{prompt}from'enquirer';constquestions=[{type: 'input',name: 'name',message: 'What is your name?',},{type: 'input',name: 'username',message: 'What is your username?',},];constresult=awaitprompt(questions);// ^? const result: object
It would be great if prompt() would infer the types from the questions object:
import{prompt}from'enquirer';constquestions=[{type: 'input',name: 'name',message: 'What is your name?',},{type: 'input',name: 'username',message: 'What is your username?',},];constresult=awaitprompt(questions);// ^? const result: { name: string; username: string; }
Alternatives considered
Pass in generics, this works today, but requires careful synchronization of the type and the questions - easy to make mistakes:
import{prompt}from'enquirer';typeResult={name: string;username: string;};constquestions=[{type: 'input',name: 'name',message: 'What is your name?',},{type: 'input',name: 'username',message: 'What is your username?',},];constresult=awaitprompt<Result>(questions);// ^? const result: { name: string; username: string; }
The text was updated successfully, but these errors were encountered:
karlhorky
changed the title
Infer object shape from question objects
TypeScript: Infer prompt() return type object shape from question objects
Jun 24, 2024
Hi, first of all, thanks for
enquirer
👍 Nice library!Currently,
enquirer
has a return type ofPromise<object>
:Playground
It would be great if
prompt()
would infer the types from thequestions
object:Alternatives considered
Pass in generics, this works today, but requires careful synchronization of the type and the questions - easy to make mistakes:
The text was updated successfully, but these errors were encountered: