Inquirer.js icon indicating copy to clipboard operation
Inquirer.js copied to clipboard

Refactor to TypeScript

Open Exortions opened this issue 2 years ago • 8 comments

Refactoring the codebase to TypeScript in my opinion would have a few advantages:

  1. Much easier to understand how things work for new/aspiring contributors
  2. Because TypeScript compiles to minified JavaScript, the bundle size for users would be smaller, and run times would be faster.
  3. Overall, it's just a good idea as Types add a lot of functionality to JavaScript.

Of course, I understand if TypeScript isn't your thing, but if it is, I'd be happy to make a PR for at least some (if not most) of the packages.

Exortions avatar Apr 13 '22 05:04 Exortions

I'm happy to review PRs starting on the new packages. I wanted to add TS, just doesn't have the time.

SBoudrias avatar Apr 13 '22 16:04 SBoudrias

With a progressive strategy and a nice roadmap, this could be done.

denik1981 avatar May 16 '22 02:05 denik1981

The first stab is launched over https://github.com/SBoudrias/Inquirer.js/pull/1112 - there's a fair amount of work, but I explained which files to focus on there. We can do them one by one!

SBoudrias avatar May 20 '22 23:05 SBoudrias

Yep, you should create a new branch for TypeScript.

Exortions avatar May 21 '22 05:05 Exortions

Nevermind, looks like you already did 😅

Exortions avatar May 21 '22 05:05 Exortions

@SBoudrias I'll be working on packages/core/src/lib/screen-manager.js.

Exortions avatar May 21 '22 05:05 Exortions

@SBoudrias I'd like to help migrate the other packages. Can I work on @inquirer/password and @inquirer/select and others if they are free as well?

I'll take @inquirer/checkbox as a reference

TDP17 avatar Jun 19 '22 08:06 TDP17

@TDP17 that'd be great! I'll leave those to you for at least a week. Feel free to send an incomplete PR if you get stuck somewhere; that way I'll know the progress and can help take the branch over if I want to wrap this up sooner 😄

SBoudrias avatar Jun 20 '22 13:06 SBoudrias

If I want to convert my plugin to typescript https://github.com/mokkabonna/inquirer-autocomplete-prompt is the approach here the way to go? Import from @inquirer/core and use the createprompt?

type SelectConfig = AsyncPromptConfig & {
  choices: { value: string; name?: string; description?: string; disabled?: boolean }[];
  pageSize?: number;
};

export default createPrompt<string, SelectConfig>((config, done) => {

mokkabonna avatar Feb 27 '23 17:02 mokkabonna

Hey @mokkabonna, yes that'd be the ideal. One thing to note is that afterward your custom prompt will be usable standalone (which I think overall is better.)

But it won't be register-able through inquirer.registerPrompt since I didn't wrap up writing the new core inquirer module yet. If you're curious, the WIP is in https://github.com/SBoudrias/Inquirer.js/pull/1173, but there's still missing a lot (and I'm considering the need to add a backward compatibility layer since otherwise all custom prompt would stop working with an eventual new major release.)

SBoudrias avatar Feb 27 '23 18:02 SBoudrias

Ok nice to know. I try to stay as aligned with what you are doing here as I can so I will then probably go down this route as well.

mokkabonna avatar Feb 27 '23 18:02 mokkabonna

I'll mark this one as complete since the new package is out and in typescript https://github.com/SBoudrias/Inquirer.js/discussions/1214

SBoudrias avatar May 19 '23 15:05 SBoudrias