Skip to content

feat(36327): libdef args rest type should always be array of any #36328

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

Closed
wants to merge 1 commit into from

Conversation

antongolub
Copy link

Fixes #36327 36327

@typescript-bot
Copy link
Collaborator

It looks like you've sent a pull request to update our 'lib' files. These files aren't meant to be edited by hand, as they consist of last-known good states of the compiler and are generated from 'src'. Unless this is necessary, consider closing the pull request and sending a separate PR to update 'src'.

@typescript-bot typescript-bot added the lib update PR modifies files in the `lib` folder label Jan 21, 2020
Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

Please move your changes to src/lib.

Additionally, it looks like you closed the source bug, so maybe this PR should be closed too.

@antongolub antongolub force-pushed the master branch 2 times, most recently from 1ae7a07 to ec983d8 Compare February 3, 2020 20:17
@antongolub
Copy link
Author

antongolub commented Feb 3, 2020

@sandersn

My issue was related to another reason, so I closed it. But I still suggest to describe ...args rest param as any[] for consistency.

@antongolub antongolub changed the title fix(36327): libdef args rest type should always be array of any feat(36327): libdef args rest type should always be array of any Feb 3, 2020
Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

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

Changing only the constraint type, as Parameters and ConstructorParameters do, should get rid of the diff in inferTypes1.types. It's not a big diff, but it's nicer to avoid any changes at all.

src/lib/es5.d.ts Outdated

/**
* Obtain the return type of a function type
*/
type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any;
type ReturnType<T extends (...args: any[]) => any> = T extends (...args: any[]) => infer R ? R : any;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
type ReturnType<T extends (...args: any[]) => any> = T extends (...args: any[]) => infer R ? R : any;
type ReturnType<T extends (...args: any[]) => any> = T extends (...args: any) => infer R ? R : any;

src/lib/es5.d.ts Outdated

/**
* Obtain the return type of a constructor function type
*/
type InstanceType<T extends new (...args: any) => any> = T extends new (...args: any) => infer R ? R : any;
type InstanceType<T extends new (...args: any[]) => any> = T extends new (...args: any[]) => infer R ? R : any;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
type InstanceType<T extends new (...args: any[]) => any> = T extends new (...args: any[]) => infer R ? R : any;
type InstanceType<T extends new (...args: any[]) => any> = T extends new (...args: any) => infer R ? R : any;

@sandersn
Copy link
Member

sandersn commented Feb 4, 2020

@typescript-bot run dt

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 4, 2020

Heya @sandersn, I've started to run the parallelized Definitely Typed test suite on this PR at a3bbc2e. You can monitor the build here. It should now contribute to this PR's status checks.

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Feb 4, 2020

Is this change going to handle ReadonlyArray and the like correctly? Does it exhibit any different behavior when inferring from two overloads, one which is a subtype of any[] and one which is only assignable to any[]?

@antongolub
Copy link
Author

@sandersn
Done.

@DanielRosenwasser
I'm afraid I can’t clarify this. My concern was just about custom IConstructable interfaces to strictly comply InstanceType internal constraint.

@sandersn
Copy link
Member

sandersn commented Feb 5, 2020

@antongolub can you add tests for the cases @DanielRosenwasser pointed out?
@DanielRosenwasser mind giving examples, particularly of the two-overload case?

@sandersn
Copy link
Member

@typescript-bot run dt

maybe it will work this time

@typescript-bot
Copy link
Collaborator

typescript-bot commented Feb 12, 2020

Heya @sandersn, I've started to run the parallelized Definitely Typed test suite on this PR at 38e6d5b. You can monitor the build here. It should now contribute to this PR's status checks.

@sandersn
Copy link
Member

@typescript-bot @weswigham DT is (almost) clean but it did not contribute to the PR's status checks that I can see.

@weswigham
Copy link
Member

Uhhh, yeah, the whole "contributes to status checks" bit was broken when we swapped to using the merge commit a few weeks ago instead of the branch head, because devops is bad. Should we swap back? IMO, forcing manual merges is probably worth the correct status linkage?

@sandersn
Copy link
Member

Not contributing to branch status is a feature rather than a bug given how broken our suite 2 tests usually are. As long as it's a known feature I'm fine with it, and I think it's better to keep perf testing the correct commit.

@sandersn
Copy link
Member

sandersn commented Mar 3, 2020

@DanielRosenwasser filed #37193 with 2 examples that behave strangely with the current definitions. We need to figure out why they behave badly before moving forward with this PR. (Checking the new definitions would be interesting too, but I suspect that they behave the same.)

@sandersn
Copy link
Member

This PR hasn't seen any activity for quite a while, so I'm going to close it to keep the number of open PRs manageable. Feel free to open a fresh PR or continue the discussion here.

@sandersn sandersn closed this Mar 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib update PR modifies files in the `lib` folder
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Lib: args rest type should always be array of any
5 participants