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
@types/node: enable strictnullchecks, fix resulting issues #20542
Conversation
types/node/index.d.ts to authors (@DefinitelyTyped/DefinitelyTyped @parambirs @tellnes @WilcoBakker @octo-sniffle @smac89 @Flarna @mwiktorczyk @wwwy3y3 @Tyriar @DeividasBakanas @kjin @alvis Microsoft TypeScript (account can't be detected)). Could you review this PR? |
Open question - I've fixed up definitions for errbacks in the tests to be Hence, should the definitions of Node builtin modules be changed to pass |
@akdor1154 Please fix the failures indicated in the Travis CI log. |
types/node/index.d.ts
Outdated
@@ -5036,6 +5038,7 @@ declare module "stream" { | |||
wrap(oldStream: NodeJS.ReadableStream): Readable; | |||
push(chunk: any, encoding?: string): boolean; | |||
destroy(error?: Error): void; | |||
_destroy(error: Error | null, cb: (e: Error | null) => any): void; |
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.
actually _destroy
gets the error passed to destroy
so I think here we have and exception to the Error | null
rule.
And I think the return type of cb
should be void
.
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.
destroy contains the call this._destroy(error || null)
- https://github.com/mcollina/node/blob/master/lib/internal/streams/destroy.js#L32 .
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.
Ah yes, you are right.
types/node/index.d.ts
Outdated
_destroy(err: Error, callback: Function): void; | ||
_write(chunk: string | Buffer | any, encoding: string, callback: (e?: Error) => any): void; | ||
_writev(chunks: Array<{ chunk: string | Buffer, encoding: string }>, callback: Function): void; | ||
_destroy(error: Error | null, cb: (e: Error | null) => any): void; |
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.
As in Readable.
types/node/index.d.ts
Outdated
@@ -123,7 +123,7 @@ interface NodeModule { | |||
id: string; | |||
filename: string; | |||
loaded: boolean; | |||
parent: NodeModule | null; | |||
parent: NodeModule | undefined; |
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 can remember that parent
may be also null
in some cases but I can't remember the exact use case.
Please adapt also the class NodeJS.Module
accordingly.
At least in source I found following new Module('internal/preload', null);
so null
is used to init parent
.
@akdor1154 Please fix the merge conflict. |
@andy-ms Documentation makes no such guarantee, convention states that null should be preferred.
Examples generally always show error checks as a check for truthiness, If this were my own project the way I would type this is add a type NodeErrBack<T, E=Error> = (error?: null | Error, result: T) => void and use it throughout |
Sure, although I would write |
should I add this to this PR? (it'll be a pretty big change, touching any function in node that takes a callback...) |
It can be in a separate PR. |
k, shall rebase+squash then continue discussion in a new PR. |
The failing lint in duplexer3 is a result of this pr. The reason is because the writable._write = (input, encoding, done) => {
if (something) {
return done();
}
..
} which is a common pattern, but fails |
Besides the first argument in callbacks also the second one is optional - if the first one is not |
Regarding the issue with duplexer3: I would vote against use of |
You don't have to change the type, you can just |
@andy-ms my point is more that |
It won't cause a lint error for people not using DT's lint configuration. So I agree with @Flarna to use the most accurate type possible, and users who don't want a lint error on |
@akdor1154 Please fix the failures indicated in the Travis CI log. |
a7f3690
to
7761e1b
Compare
@akdor1154 could you fix the test failures? |
I'm closing this PR due to lack of activity. If you would still like to get in these changes, please open a new PR. Thank you! |
Please fill in this template.
npm run lint package-name
(ortsc
if notslint.json
is present).Select one of these and delete the others:
If changing an existing definition:
null
in docs.tslint.json
containing{ "extends": "dtslint/dt.json" }
.Update @types/node to successfully work with strictNullChecks: true. Also var -> let in node-tests.ts. The first commit just fixes the "use before declaration" errors local to
node-tests
, the rest go on to fix the actual declaration problems detected as a result.I am a bit confused that I was unable to find any existing discussion over this, sorry if I am unwittingly stomping all over existing drama.
-- Jarrad