Hi, first of all, thanks for enquirer 👍 Nice library!
Currently, enquirer has a return type of Promise<object>:
import { prompt } from 'enquirer';
const questions = [
{
type: 'input',
name: 'name',
message: 'What is your name?',
},
{
type: 'input',
name: 'username',
message: 'What is your username?',
},
];
const result = await prompt(questions);
// ^? const result: object
Playground
It would be great if prompt() would infer the types from the questions object:
import { prompt } from 'enquirer';
const questions = [
{
type: 'input',
name: 'name',
message: 'What is your name?',
},
{
type: 'input',
name: 'username',
message: 'What is your username?',
},
];
const result = await prompt(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';
type Result = {
name: string;
username: string;
};
const questions = [
{
type: 'input',
name: 'name',
message: 'What is your name?',
},
{
type: 'input',
name: 'username',
message: 'What is your username?',
},
];
const result = await prompt<Result>(questions);
// ^? const result: { name: string; username: string; }
Hi, first of all, thanks for
enquirer👍 Nice library!Currently,
enquirerhas a return type ofPromise<object>:Playground
It would be great if
prompt()would infer the types from thequestionsobject:Alternatives considered
Pass in generics, this works today, but requires careful synchronization of the type and the questions - easy to make mistakes: