-
-
Notifications
You must be signed in to change notification settings - Fork 935
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
Make the TypeScript types strict and better #849
Conversation
@sindresorhus as soon as form-data/form-data#435 or DefinitelyTyped/DefinitelyTyped#37331 is merged we could merge just this commit if you want to. It adds strict type checkin to the library part, and enforces it with an extra Or we could wait for me to finish typing the tests |
// @vladfrangu FYI |
I would prefer merging this when it passes first. Smaller PRs are good and makes it less likely to conflict with other changes. |
Co-Authored-By: Sindre Sorhus <sindresorhus@gmail.com>
Running into microsoft/TypeScript#32693 when upgrading to TS 3.5 😬 |
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.
👍 from me, past these few questions/nits
|
||
if (socketPath || net.isIP(hostname || host)) { | ||
if (socketPath || net.isIP(hostname || host || '')) { |
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 see that this net.isIP check is used at least twice, can't we abstract it to one central variable?
@@ -32,7 +35,7 @@ export default (request: ClientRequest, delays: Delays, options: TimedOutOptions | |||
const cancelers: Array<typeof noop> = []; | |||
const {once, unhandleAll} = unhandler(); | |||
|
|||
const addTimeout = (delay: number, callback: (...args: unknown[]) => void, ...args: unknown[]): (typeof noop) => { | |||
const addTimeout = <T extends any[]>(delay: number, callback: (delay: number, ...args: T) => void, ...args: T): (typeof noop) => { |
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.
Does the callback actually take the delay as the first argument? it doesn't seem like it
TypeScript 3.6 is out. Maybe that fixes some bugs? https://devblogs.microsoft.com/typescript/announcing-typescript-3-6/ |
@LinusU ping 😉 |
See #849 Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
I've pulled the current changes of this PR into master as I plan to do an early alpha release: 5002e54 |
I have upgraded TS to latest now: 640c30b |
@yovanoc Why? There's no need. |
Check yourself, with NodeJS setTimeout return a number and global.setTimeout return a NodeJS.Timeout |
I did and you're wrong:
|
@@ -91,7 +94,7 @@ export default (request: ClientRequest, delays: Delays, options: TimedOutOptions | |||
|
|||
if (delays.socket !== undefined) { | |||
const socketTimeoutHandler = (): void => { | |||
timeoutHandler(delays.socket, 'socket'); | |||
timeoutHandler(delays.socket!, 'socket'); |
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.
Shouldn't the if statement act as a type guard, thus removing the need for the non-null assertion? Likewise in a few other places.
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.
Already fixed in master: 640c30b#diff-7ab9a52ac2fccf434c1a34ce48f2883bL95-R95
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, my mistake! 👍
Closing for lack of activity. |
Sorry for dragging my feet on this, closing is definitely the right approach 👍 Hopefully I'll get some time to work on this later |
Blocked on: form-data/form-data#435 or DefinitelyTyped/DefinitelyTyped#37331
Next steps:
test/**/*.ts
conform to strict modetsconfig.json
There is currently 1218 TypeScript errors in test files when running in strict mode 😂
Will submit some typings upstream and then type everything up!