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

inquirer@10.1.6 has a missing type for message in prompt function #1495

Closed
mikeseese opened this issue Aug 1, 2024 · 6 comments
Closed

inquirer@10.1.6 has a missing type for message in prompt function #1495

mikeseese opened this issue Aug 1, 2024 · 6 comments

Comments

@mikeseese
Copy link

mikeseese commented Aug 1, 2024

I have this code:

const response = await inquirer.prompt({
  type: "confirm",
  name: "continue",
  message: `\twhats up?`,
  default: false,
});

but the types included in inquirer@10.1.6 provide an error for message (I was sure to uninstall @types/inquirer during my upgrade from v9):

image

It seems that message is missing from QuestionMap:

export interface QuestionMap {
input: Parameters<typeof input>[0];
select: Parameters<typeof select>[0];
/** @deprecated `list` is now named `select` */
list: Parameters<typeof select>[0];
number: Parameters<typeof number>[0];
confirm: Parameters<typeof confirm>[0];
rawlist: Parameters<typeof rawlist>[0];
expand: Parameters<typeof expand>[0];
checkbox: Parameters<typeof checkbox>[0];
password: Parameters<typeof password>[0];
editor: Parameters<typeof editor>[0];
}

but the missing type is being referenced by PromptConfigMap:

message:
| Pick<QuestionMap[keyof QuestionMap], 'message'>
| AsyncGetterFunction<
Pick<QuestionMap[keyof QuestionMap], 'message'>,
Prettify<A>
>;

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
@SBoudrias
Copy link
Owner

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?

@mikeseese
Copy link
Author

mikeseese commented Aug 1, 2024

Wrapping it in an array does not work:

image

I'm using typescript@5.4.5; 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;
}

@SBoudrias
Copy link
Owner

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.

@mikeseese
Copy link
Author

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

@mikeseese
Copy link
Author

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 🤷

@SBoudrias
Copy link
Owner

We released new core types today with inquirer@10.2.0. Would appreciate people trying it out and bringing feedback - cheers!

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

No branches or pull requests

2 participants