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

Add [Constructor]Parameters types to lib.d.ts #26243

Merged
merged 1 commit into from
Aug 31, 2018

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Aug 6, 2018

Based on #26042 and discussion from the most recent design meeting. Thanks @anurbol for creating the initial PR.

It turns out that our tests have a couple of examples of looser definitions of Parameters. The differences are instructive:

type Parameters<T extends Function> = ((...args: infer U) => any) | (new (...args: infer U) => any) ? U : any[];

This looser definition allows:

  1. Function to create an array of parameters any[].
  2. Either constructors or functions to be passed in.
  3. Tuple-constrained type parameters, for example T extends any[] to be used as the type of rest parameters.

(1) is pretty questionable and is fine to disallow, I think. (2) is now handled by Parameters vs ConstructorParameters. (3) is unsound, as pointed out in #26013, since it is equivalent to allowing the assignability of T extends any[] to any[]. So I think all 3 differences are improvements. I preserved them in the test baselines.

Fixes #26019

@mattmccutchen
Copy link
Contributor

There were three questions involving Parameters on Stack Overflow just today: 1, 2, 3. It would be great if Parameters got into the standard library before more people have to copy it into their own projects.

@sandersn sandersn merged commit c929e74 into master Aug 31, 2018
@sandersn sandersn deleted the add-parameter-to-tuple-type branch August 31, 2018 14:46
@sandersn
Copy link
Member Author

Looks like this broke the build because we now elaborate errors more often. I'll send a follow-up PR that updates the baselines with more elaborations.

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.

None yet

3 participants