Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

LinusU
Copy link
Contributor

@LinusU LinusU commented Aug 3, 2019

Blocked on: form-data/form-data#435 or DefinitelyTyped/DefinitelyTyped#37331

Next steps:

There is currently 1218 TypeScript errors in test files when running in strict mode 😂

Will submit some typings upstream and then type everything up!

@LinusU
Copy link
Contributor Author

LinusU commented Aug 3, 2019

@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 tsc call in the test phase.

Or we could wait for me to finish typing the tests ☺️

@sindresorhus
Copy link
Owner

// @vladfrangu FYI

@sindresorhus
Copy link
Owner

Or we could wait for me to finish typing the tests ☺️

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>
@LinusU
Copy link
Contributor Author

LinusU commented Aug 4, 2019

Running into microsoft/TypeScript#32693 when upgrading to TS 3.5 😬

Copy link
Contributor

@vladfrangu vladfrangu left a 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 || '')) {
Copy link
Contributor

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) => {
Copy link
Contributor

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

source/utils/timed-out.ts Show resolved Hide resolved
@sindresorhus
Copy link
Owner

TypeScript 3.6 is out. Maybe that fixes some bugs? https://devblogs.microsoft.com/typescript/announcing-typescript-3-6/

@szmarczak
Copy link
Collaborator

@LinusU ping 😉

sindresorhus added a commit that referenced this pull request Sep 17, 2019
See #849

Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
@sindresorhus
Copy link
Owner

I've pulled the current changes of this PR into master as I plan to do an early alpha release: 5002e54

@sindresorhus
Copy link
Owner

I have upgraded TS to latest now: 640c30b

@yovanoc
Copy link

yovanoc commented Sep 24, 2019

Hello, you have to put global. before setInterval and setTimeout to handle NodeJS properly, thanks.

image

@szmarczak
Copy link
Collaborator

@yovanoc Why? There's no need.

@yovanoc
Copy link

yovanoc commented Sep 24, 2019

Check yourself, with NodeJS setTimeout return a number and global.setTimeout return a NodeJS.Timeout

@szmarczak
Copy link
Collaborator

I did and you're wrong:

$ node
Welcome to Node.js v12.10.0.
Type ".help" for more information.
> setTimeout(() => {}, 1000);
Timeout {
  _idleTimeout: 1000,
  _idlePrev: [TimersList],
  _idleNext: [TimersList],
  _idleStart: 20031,
  _onTimeout: [Function],
  _timerArgs: undefined,
  _repeat: null,
  _destroyed: false,
  [Symbol(refed)]: true,
  [Symbol(asyncId)]: 98,
  [Symbol(triggerId)]: 5
}
> global.setTimeout(() => {}, 1000);
Timeout {
  _idleTimeout: 1000,
  _idlePrev: [TimersList],
  _idleNext: [TimersList],
  _idleStart: 43542,
  _onTimeout: [Function],
  _timerArgs: undefined,
  _repeat: null,
  _destroyed: false,
  [Symbol(refed)]: true,
  [Symbol(asyncId)]: 272,
  [Symbol(triggerId)]: 5
}

@@ -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');
Copy link
Contributor

@samhh samhh Oct 1, 2019

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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, my mistake! 👍

@sindresorhus
Copy link
Owner

Closing for lack of activity.

@LinusU
Copy link
Contributor Author

LinusU commented Nov 1, 2019

Sorry for dragging my feet on this, closing is definitely the right approach 👍

Hopefully I'll get some time to work on this later ☺️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants