listr2 icon indicating copy to clipboard operation
listr2 copied to clipboard

Upcoming TypeScript changes to Enquirer

Open smithki opened this issue 3 years ago • 7 comments

I wanted to leave a trace here about a promising PR in the enquirer repo regarding TypeScript definitions (https://github.com/enquirer/enquirer/pull/307).

I understand that the typings provided by listr2 are an internal reproduction of Enquirer's typings, although they are incomplete. Hopefully once the above PR is merged and published, the custom typings in listr2 can be removed!

Thanks for all the hard work on this great package btw! I love the developer experience here 🚀

smithki avatar Dec 22 '20 14:12 smithki

Oh that is just great news. I will have a look when the PR gets merged and update accordingly.

Thanks for the heads up and kind words.

cenk1cenk2 avatar Dec 22 '20 14:12 cenk1cenk2

Pretty new to the TS world here. Does the above have anything to do with the below?

node_modules/listr2/dist/utils/prompt.interface.d.ts:2:22 - error TS2307: Cannot find module 'enquirer' or its corresponding type declarations.

node_modules/listr2/dist/interfaces/listr.interface.d.ts:2:22 - error TS2307: Cannot find module 'enquirer' or its corresponding type declarations.

mikerockett avatar Dec 27 '20 13:12 mikerockett

Na. This is because I export the prompt.interface.ts from index.ts and since you call the package by index it goes through and parses every import in indivudual files. I import enquirer in prompt.interface.ts for prompt types, so you have to explicitly install enquirer for typescript not going crazy.

You can solve this by installing enquirer as dev dep if you are not going to use it. I am not sure how can fix this shortcoming.

cenk1cenk2 avatar Dec 27 '20 13:12 cenk1cenk2

Perfect, needed to enable module interop as well as it was moaning about default imports. Thanks!

mikerockett avatar Dec 27 '20 14:12 mikerockett

Np. Sorry that it is a bit of shortcoming.

cenk1cenk2 avatar Dec 27 '20 15:12 cenk1cenk2

I guess this will never get merged to the upstream library.

cenk1cenk2 avatar Jun 09 '22 22:06 cenk1cenk2

Another option is to pull those (correct) typings into listr2 and use them directly. I've done this myself in the past: https://github.com/smithki/zombi/blob/master/packages/zombi/src/types/enquirer.ts

Or... maybe it's time for yet another Node.js prompt package. Not a single one has satisfactory TypeScript support in my experience.

smithki avatar Jun 09 '22 23:06 smithki

Closing this because of being stale and the enquirer receiving no updates. I will add this to looking for contributions section if somebody wants to give it a go.

cenk1cenk2 avatar Apr 01 '23 23:04 cenk1cenk2