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

Update TypeScript types, check types against JavaScript tests/examples #307

Open
wants to merge 98 commits into
base: master
Choose a base branch
from

Conversation

bitjson
Copy link

@bitjson bitjson commented Aug 4, 2020

Still a work in progress – I'm just trying to get @unional's fantastic work on #261 over the finish line.

This PR builds on #261 – I've removed the duplicated set of tests (which were being used to develop the types), and instead I'm checking the rest of the repo (guide, examples, lib, recipes, test) with the new types. I also reverted some formatting changes to keep this PR as thin as possible.

There are ~500 TS issues remaining (many of which were already marked as TODO by @unional), but once these issues are fixed, the types should be very complete, and much easier to maintain (npm test now validates them). If you're interested in helping, please send PRs to this branch, and I'll merge them to add them to this PR.

Closes #82
Closes #135
Closes #202
Closes #204
Closes #212
Closes #252
Closes #258
Closes #261
Closes #262
Closes #263
Closes #286

@bitjson bitjson marked this pull request as ready for review August 7, 2020 18:40
@bitjson
Copy link
Author

bitjson commented Aug 7, 2020

Ok, I cleaned up a few more issues – there are still places we need to improve, but I think we're in a good spot to make smaller, iterative changes now. (Especially now that we're testing against the actual JS examples.)

@jonschlinkert would you be willing to merge these TypeScript changes? Is there anything else you'd like me change?

@@ -9,3 +9,5 @@ node_js:
- '11'
- '10'
- '8'
before_script:
- cd examples && npm install && cd ../guide && npm install && cd ..
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the examples use external dependencies which aren't in the top-level package.json, so we have to install them before running tsc in Travis. (Otherwise TypeScript throws errors for missing dependencies.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@bitjson
Copy link
Author

bitjson commented Aug 10, 2020

(I force-pushed to retry CI. Tests on Node.js 8 fail randomly – not related to this PR, which doesn't touch any JS.)

Copy link
Member

@jonschlinkert jonschlinkert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code is breaking some SOLID principles

Yeah, there are tradeoffs. If you've seen any of my other libraries, I'm a big fan of SOLID principles, I tend to favor responsibility libraries. IMHO, in Enquirer the benefits of inheritance far outweigh the advantages of SOLID, from the standpoints of both maintenance and implementation. It's just too much work to redefine everything on every class, and repeated code everywhere lends itself to inconsistencies when minor improvements or tweaks are made.

(I force-pushed to retry CI. Tests on Node.js 8 fail randomly – not related to this PR, which doesn't touch any JS.)

I think it's related to a dev dependency (time-require I think). Don't worry about it, I'll get that fixed. If that is indeed what's causing it, I'll either fix the node version inconsistency or just remove that unnecessary dev dep.

I'm still looking through, but I'd love to get this merged. I'm getting caught up. Please let me know if you think it's ready. I just #307 (comment) but missed that earlier. Sounds good!

@@ -9,3 +9,5 @@ node_js:
- '11'
- '10'
- '8'
before_script:
- cd examples && npm install && cd ../guide && npm install && cd ..
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@bitjson
Copy link
Author

bitjson commented Sep 8, 2020

@jonschlinkert thanks for taking a look! Please let me know if there's anything else you'd like me to change before merging this. 🚀

I'm current using a version of this PR in my development branch of Bitauth CLI, where I'm continuing to improve the types as needed.

After this PR is merged, future PRs should have much smaller diffs and only increase "TypeScript coverage". (In this PR, only a few examples are "covered", but we can slowly expand that list until it includes everything in the examples, guide, and test directories.)

@jonschlinkert
Copy link
Member

@bitjson I'm amazed at the amount of effort that you, @unional and others have put into adding typescript support. You are very much appreciated!

@doowb and I have both looked over the code, neither of us had any issues at all running the code. One of us will try to get these changes merged in ASAP. Thanks!

@linzhiq
Copy link

linzhiq commented Nov 2, 2020

^ any update on this 😬

@KamalAman
Copy link

@jonschlinkert / @doowb 🙏 💖 🙏 Getting this in would be very much appreciated 🙏 💖 🙏

@kherock
Copy link

kherock commented Nov 26, 2020

👍 Just confirming that these changes work great in a CLI project I'm writing in TS, would really appreciate if these changes made in in soon!

@bitjson
Copy link
Author

bitjson commented Feb 1, 2021

Hey @jonschlinkert and @doowb, I think this has been well-reviewed by some of the above commenters, and the changes are contained to only TypeScript-related parts of the project. (It also resolves/closes 11 other issues and PRs! 😄)

I think merging is pretty low-risk now: would it be possible to get this released soon?

@eleith
Copy link

eleith commented Mar 10, 2021

as a workaround till this lands, you can update your tsconfig.json to use the types provided by this branch as follows (the below example assumes you download index.d.ts from this branch to types/enquirer.d.ts)

{                                                                                                                                                                                                                
   "compilerOptions": {                                                                                                                                                                                                                                                                                                                                                                                   
     "paths": {                                                                                                                                                                                                   
       "enquirer": ["./types/enquirer.d.ts"]                                                                                                                                                                      
     }                                                                                                                                                                                                            
   }                                                                                                                                                                                                                                                                                                                                                                                          
}  

@ericvera
Copy link

ericvera commented Apr 27, 2021

Thanks @eleith for the workaround! In case someone runs into issues with the solution you also need to set baseUrl for this paths work.

{
 "compilerOptions": {
   "baseUrl": ".",
   "paths": {
     "enquirer": ["./types/enquirer.d.ts"]
   }
 }                                                                                                                                                                                                                                                                                                                                                                              }  

@youbek
Copy link

youbek commented Jan 30, 2022

Any updates on this? Thanks :)

@lenovouser
Copy link

I've tested this as well, seems to work flawlessly so far. Can this be merged @jonschlinkert and @doowb?

@bestickley
Copy link

Using TypeScript, would really appreciate for this to be merged.

@D3SOX
Copy link

D3SOX commented Apr 12, 2022

I encountered some issues while trying to use these definitions

  • Many SymbolsTypes are missing
    image

  • Can't find Type here
    image

  • And an interesting warning here
    image

I would like to use Enquirer because it supports more prompts ootb but for the moment Inquirer seems to be a better maintained project

Options &
types.Initializer<string | number, string> &
types.Formatter<string, string>;
export type MultipleOptions = { multiple: true } & Type &
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Type & seems superfluous, it resolves to nothing in my local setup. Similar on SingleOptions in this namespace.

@ProdigySim
Copy link

A couple enhancements that would be nice to have (for a V2): prompt(question) should have its Answer type inferred from the question input. This is a trickier task, but I've got some initial work here that accomplishes it for a few of the supported prompt types:

https://gist.github.com/ProdigySim/73913e526d12719476582238a3fce2aa

Supports:

  • input
  • numeral
  • invisible
  • password
  • list
  • autocomplete

Missing:

  • select
  • multiselect
  • quiz
  • ???

@rebeccahum
Copy link

rebeccahum commented May 9, 2024

Hi! We are seeing that the type definition for ConfirmQuestionOptions is expecting a string for the initial property, however, it should allow a boolean per

this.default = this.options.default || (this.initial ? '(Y/n)' : '(y/N)');

I think we need to change initial?: T | ( () => Promise< T > | T ); to initial?: T | ( () => Promise< T > | T ) | boolean | ( () => Promise< boolean > | boolean ); under export type Question< T extends types.Answer = string, P extends Prompt< T > = Prompt< T > > = {

Thankssss

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment