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
On the road to typescript #1586
Comments
I'm currently working on the 1st step |
@mleguen I have a thought about the final conversion of
@cameronhunter I saw that you've contributed to |
Some thoughts: As a first step you could pull the type definitions into As long as you conform to the type interface, the migration of the implementation to TS should just be patch releases. Eventually when your migration is complete you can publish types generated from your TS instead of maintaining the type interface manually. |
@bcoe @cameronhunter I modified the proposed type naming strategy to integrate your suggestions. Would that be OK for you? |
@mleguen "5." looks great. |
@mleguen I've added additional functionality to our publication that allows us to publish candidate releases (just add the label Doing this I released a candidate release of yargs with your TypeScript work ... It's pretty darn close to the same size as our non-typescript release at this point:
vs.,
This makes me happy and is really promising If any of us interested in this work have the cycles, I suggest trying out |
I'm roughly halfway now of converting I knew it would be the hardest part, but on the way I am learning much on yargs inner workings, and honing my type inference skills too, so I enjoy the ride! :-) |
@mleguen anything I can do to pitch in on the conversion of |
@bcoe Sure. I finished debugging on Friday, and should be able to push a PR after a final review on my side by Tuesday or Wednesday. This PR will not yet include type inference on parse arguments, as @types/yargs does, as it would increase the review delay and complexity. This will have to be done later when working on d.ts files. |
Feature Request: My colleague brought up the fact that if you have validation and coercion right now, you don't get good typing information. Basically, he would like to coerce an option, after applying validation. You could do something like this with |
Mind a small example? |
@mleguen here's where my colleague was attempting to use https://github.com/grpc/grpc-node/pull/1474/files#diff-30899751cdd83c7ea9d8e583f66504c6R528 The problem is that coerce runs prior to |
We ultimately decided to continue pointing the community towards It's a significant benefit to the project to be written in TypeScript, for maintainers, but tdlr; we're put in the position of either:
I could imagine revisiting this decision in the future, or perhaps taking an alternate approach like shipping types separately. |
Here is a proposal about how to migrate progressively to typescript, to:
Proposed steps:
a first merge request to:convert to typescript a first module, not depending on any other yargs' module (is-promise
could be a good choice), renaming it fromlib/module.js
tolib/module.ts
(compiled version:build/lib/module.js
andbuild/lib/module.d.ts
for its types)adapt other modules depending on this one to look for it inbuild
and initialize typescript's configuration, dependencies and packaging scripts for this module to have only its compiled version in the final npm package (transparent for users)several other merge requests to convert to typescript all other modules in libmove most ofyargs.js
tolib/yargs.ts
to keep it as a nearly empty shell (see below)keepindex.js
andyargs.js
at the root of the project, mostly as empty shells importing typescript-built modules, to keep yargs require calls untouched in calling js code:const yargs = require('yargs')
orconst yargs = require('yargs/yargs')
(changing toconst { yargs } = require('yargs')
would be necessary if we exposed directly typescript-built modules)index.d.ts
andyargs.d.ts
at the root of the project, for calling ts code to be able to access our types (mostly empty shells too)start with the type definitions in@types/yargs
@types/yargs
, keep old names as aliases to avoid a breaking change for ts users@types
to add module definitions for other dependenciesEDITS: fixed typo, updated progress, review type naming strategy
The text was updated successfully, but these errors were encountered: