`[email protected]` has a missing type for `message` in prompt function
I have this code:
const response = await inquirer.prompt({
type: "confirm",
name: "continue",
message: `\twhats up?`,
default: false,
});
but the types included in [email protected] provide an error for message (I was sure to uninstall @types/inquirer during my upgrade from v9):
It seems that message is missing from QuestionMap:
https://github.com/SBoudrias/Inquirer.js/blob/2cc9e311a38b8074fd1b30c073f3a7a506c8c75f/packages/inquirer/src/types.mts#L29-L41
but the missing type is being referenced by PromptConfigMap:
https://github.com/SBoudrias/Inquirer.js/blob/2cc9e311a38b8074fd1b30c073f3a7a506c8c75f/packages/inquirer/src/types.mts#L52-L57
I confirmed that the logic works if I ignore the type:
yarn run v1.22.22
$ ts-node packages/deployment/src/docker/script.ts template-match-staging
? whats up? (y/N
Does it work with an array? inquirer.prompt([{ ... }])?
It's weird because there's multiple tests covering those... Which version of TS are you using? Did you try updating it?
Wrapping it in an array does not work:
I'm using [email protected]; Updating to 5.5.4 doesn't fix it. I can also confirm that the error is prompted in VSCode, ts-node, and tsc.
The code works if the type is ignored or if the tests are using a transpile only flag (and not type checking), so perhaps that could be why the tests are passing (I haven't looked at them myself)?
Note, my original analysis of how QuestionMap was missing message was just wrong; I misunderstood how the typing is working, but it makes sense now.
~~Changing QuestionMap to this seems to resolve the issue:~~ EDIT: This is also wrong, it allows me to set message to any type
export interface QuestionMap {
input: typeof input;
select: typeof select;
/** @deprecated `list` is now named `select` */
list: typeof select;
number: typeof number;
confirm: typeof confirm;
rawlist: typeof rawlist;
expand: typeof expand;
checkbox: typeof checkbox;
password: typeof password;
editor: typeof editor;
}
Not a direct solution to your issue that I didn't have time to investigate (also, weirdly I've been able to migrate another TS codebase successfully to v10 🤷🏻)
But, did you consider switching to @inquirer/prompts? It's a much simpler interface, and has good strong typings. inquirer interfaces are old and very complex to type properly due to the old-style node patterns it relies upon.
I thought about it for about 5 seconds before I saw "rewrite" and noped out haha. I'll give it a shot later today hopefully
I moved to @inquirer/prompts and everything is working (understandably due to the much simpler types/usage. I even prefer the interface in @inquirer/prompts. Thanks for the gentle nudge! Up to you if you want to close this as a wont-fix or stating the solution is to upgrade/downgrade 🤷
We released new core types today with [email protected]. Would appreciate people trying it out and bringing feedback - cheers!