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
Split node into one file per module #32567
Conversation
@RyanCavanaugh, @DanielRosenwasser: Do you have any thoughts on this change? This was recommended by @Flarna and @KonanMentor as something worth doing as part of adding |
@rbuckton Thank you for submitting this PR! 🔔 @microsoft @DefinitelyTyped @jkomyno @a-tarasyuk @alvis @r3nya @BrunoScheufler @smac89 @tellnes @DeividasBakanas @eyqs @Flarna @Hannes-Magnusson-CK @KSXGitHub @hoo29 @kjin @ajafff @islishude @mwiktorczyk @matthieusieben @mohsen1 @n-e @octo-sniffle @parambirs @eps1lon @SimonSchick @ThomasdenH @WilcoBakker @wwwy3y3 @ZaneHannanAU @jeremiergz @samuela - please review this PR in the next few days. Be sure to explicitly select If no reviewer appears after a week, a DefinitelyTyped maintainer will review the PR instead. |
Honestly speaking I'm still not sure if typesversion is something we want to have at all as it just increases the maintenance burden - it's still needed to type everything for 2.1. Personally I would prefer to raise the minimum typescript version like it was done in other modules (e.g. react used min version 2.8). Are there any plans to move forward in this? Currently the use if it blocks node changes anyway as CI fails in jsdom and since a few hours additionally in google-cloud__tasks (see #32444). If the decisions is to use typesversions splitting files is a good idea in my opinion. Most likely tests need to be splitted also as they will differ also between typescript version once the definitions itself are version specific. It would be also good to have a better separation between the subfolders created for typescript versions and that ones created because of node versions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this a few months ago but ran into a few roadblocks (tests weren't able to import modules for some reason), good job!
This will make maintaining these typings drastically easier!
Some notes:
We should probably try to avoid defining modules in global
and instead try to have global
import those from the respective module definitions, see module, process, etc.
Optional: We can probably cleanup imports a fair bit, eg. replace wildcard imports with more specific ones.
@@ -0,0 +1,3 @@ | |||
declare module "process" { | |||
export = process; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Shouldn't this file contain the actual process definitions and the global should reference this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its a bit tricky to define it that way, since you cant import
a module into the global scope. You can add a global augmentation inside the module, however:
declare module "process" {
global {
var process: NodeJS.Process;
...
}
export = process;
}
However I don't want to dramatically change the shape of the NodeJS API in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fine.
@@ -0,0 +1,3 @@ | |||
declare module "module" { | |||
export = NodeJS.Module; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment at module.d.ts
Unfortunately, We can discuss this more within the TypeScript team, but the folder structure we are using now is what we've decided on and are currently enforcing in both dtslint and types-publisher. |
@Flarna is 2.x even officially supported anymore eg. is 2.x on LTS? |
Also, should test files be split too? |
Also once this PR lands I will look into updating typings for node v11. |
@rbuckton The Travis CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
I did a closer look into the changes and tried them in my local setup - it works. I would also prefer to move at least parts from global.d.ts (e.g. |
@Flarna: Should it matter that the definition for |
If necessary we should do this in a follow-on PR. |
@rbuckton The Travis CI build failed! Please review the logs for more information. Once you've pushed the fixes, the build will automatically re-run. Thanks! |
Tests look good, the only failing tests are due to the recent addition of |
Honestly speaking I don't know why the definition of node (e.g. use namespace NodeJS,..) is done that way. I guess because it was created before typescript 2.0 even existed and at that time some augmentations of e.g. classes or so were not possible. |
@Flarna, @SimonSchick I may have to revert this change and go back to the previous approach to support |
Right now it's also not really possible for libraries to move away from it either (from my understanding). E.g. import {ReadStream} from 'tty';
import process from 'process';
const stream: ReadStream = process.stdin; gets EDIT: Ergh, I guess this would solve that:
Are there any plans/issue for this? In order to start fixing e.g. jestjs/jest#8092 it seems we have to be able to move off of |
I think the biggest painpoint/reason that this namespace exists was that global definitions cannot use imports from modules? But yea, getting rid of the |
Per #30477 (comment) and #30477 (comment), this splits node's definitions into one file per module in advance of leveraging
"typesVersions"
support.