@types/node: enable strictnullchecks, fix resulting issues#20542
@types/node: enable strictnullchecks, fix resulting issues#20542akdor1154 wants to merge 9 commits intoDefinitelyTyped:masterfrom
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. |
| 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.
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.
destroy contains the call this._destroy(error || null) - https://github.com/mcollina/node/blob/master/lib/internal/streams/destroy.js#L32 .
| _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; |
| filename: string; | ||
| loaded: boolean; | ||
| parent: NodeModule | null; | ||
| parent: NodeModule | undefined; |
There was a problem hiding this comment.
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) => voidand 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(ortscif notslint.jsonis present).Select one of these and delete the others:
If changing an existing definition:
nullin docs.tslint.jsoncontaining{ "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