Skip to content

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

Merged
Nathan Shively-Sanders (sandersn) merged 1 commit into
masterfrom
add-parameter-to-tuple-type
Aug 31, 2018
Merged

Add [Constructor]Parameters types to lib.d.ts#26243
Nathan Shively-Sanders (sandersn) merged 1 commit into
masterfrom
add-parameter-to-tuple-type

Conversation

@sandersn

Copy link
Copy Markdown
Member

Based on #26042 and discussion from the most recent design meeting. Thanks Nurbol Alpysbayev (@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
Copy Markdown
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
Nathan Shively-Sanders (sandersn) deleted the add-parameter-to-tuple-type branch August 31, 2018 14:46
@sandersn

Copy link
Copy Markdown
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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants