-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
lib: fix internalBinding type definitions #47373
Conversation
Review requested:
|
Ah, I can sorta see why things aren't working, or working strangely. Because Node's internals are not really modules, I think TS is detecting them as scripts all loaded into the same scope. That's probably hidden by not actually having checking enabled. I don't know how much work it'd be, but adding a tsconfig and adding allowJs/checkJs/noEmit might be interesting to try. In the meantime, another pattern that you can use instead and keep the let is to instead use interface merging to declare the type of this. What you'd do is restore the For example, declare interface InternalBinding {
(binding: 'config'): {
isDebugBuild: boolean;
hasOpenSSL: boolean;
fipsMode: boolean;
hasIntl: boolean;
hasTracing: boolean;
hasNodeOptions: boolean;
hasInspector: boolean;
noBrowserGlobals: boolean;
bits: number;
hasDtrace: boolean;
}
} This is the same approach used by the lib.d.ts files to add more overloads depending on the different lib target set in tsconfig. Here's a patch you can apply if you revert the |
Adding a tsconfig file even if it doesn't have checkJs enabled may be desirable just so you can explicitly ensure that the d.ts files are loaded. Right now, I think they might only show up if you have opened the files in the editor. Then afterward, you may be able to set EDIT: I missed that you had a tsconfig already. Oops. |
It seems to be working? Some of them don't work because there are things missing from It may be better to keep your renaming change, though, and then use the simpler option of overloads instead. It doesn't seem like the name matters in this loader file? |
Current changes +
Did you get it working with this PR changes + the git diff you've shared? I couldn't get it to working... |
With this PR, reverting the Another thing that worked without scope sharing was to instead declare |
It didn't work for me (both VSCode and Webstorm), it still detects |
Very very strange. Most of these work, but worker does not. I'm not sure what's going on here. You probably don't want to load DOM to get URL; you'll pull in a load of stuff that won't work. You may just want to re-declare it locally, or copy from URL in |
de5b278
to
152d00a
Compare
Agreed. Removed it for the time being. |
Within this PR, vscode works (including Maybe it's a cache problem in vscode (The ts server is buggy if it runs very long, have to restart it). Try restart ts service on your vscode. Also online vsode works: https://gitpod.io/#https://github.com/nodejs/node/pull/47373/ CleanShot.2023-04-03.at.11.36.39-converted.mp4 |
@gengjiawen My main goal was to fix the Clion types... I'll leave this as a draft until I find a fix for Clion too... |
5d6d494
to
8e65c90
Compare
From what I test, latest code not working for vscode. |
Thanks for testing @gengjiawen. I'll take a look at it |
3532f6d
to
2ebdf07
Compare
@gengjiawen can you try it again? |
2ebdf07
to
1d3edf1
Compare
still not working. |
OK, I'm officially giving up on this. Feel free to continue, if anyone is interested. |
@anonrig make it work on vscode enough for most people, we can take fix clion maybe later, reopen it ? |
Work in progress.
Current type definitions does not work for me. Investigating the issue. Full conversation is available on Twitter: https://twitter.com/andhaveaniceday/status/1642583763862552576?s=61&t=MpgxJm-yQa5OwwXgT9yE6A