Skip to content

feat(lib/es2015): Add typed overloads to Reflect - #35608

Merged
Nathan Shively-Sanders (sandersn) merged 2 commits into
microsoft:mainfrom
ExE-Boss:lib/es2015/typed-reflect
Aug 9, 2022
Merged

feat(lib/es2015): Add typed overloads to Reflect#35608
Nathan Shively-Sanders (sandersn) merged 2 commits into
microsoft:mainfrom
ExE-Boss:lib/es2015/typed-reflect

Conversation

@ExE-Boss

@ExE-Boss ExE Boss (ExE-Boss) commented Dec 10, 2019

Copy link
Copy Markdown
Contributor

This adds typed overloads to Reflect, similar to what strictBindCallApply does.

I’ve also corrected the type of getPrototypeOf(…) and setPrototypeOf(…). (extracted into #41987)

Depends on:

Comment thread src/lib/es2015.reflect.d.ts Outdated
* @param argumentsList An array of argument values to be passed to the function.
*/
function apply<T, A extends any[], R>(target: (this: T, ...args: A) => R, thisArgument: T, argumentsList: A): R;
function apply(target: (...args: any) => any, thisArgument: any, argumentsList: ArrayLike<any>): any;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This second overload will just be picked by the compiler whenever anything fails to be accepted by the first overload, so this doesn't really add strictness. Better autocomplete, I guess.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, this is needed to be able to pass the arguments object.

Comment thread src/lib/es2015.reflect.d.ts Outdated
* @param newTarget The constructor to be used as the `new.target` object.
*/
function construct<A extends any[], R>(target: new (...args: A) => R, argumentsList: A, newTarget?: new (...args: any) => any): R;
function construct(target: new (...args: any) => any, argumentsList: ArrayLike<any>, newTarget?: new (...args: any) => any): any;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same here, the second overload makes the first one useless 😢

Comment thread src/lib/es2015.reflect.d.ts
Comment thread src/lib/es2015.iterable.d.ts Outdated
@typescript-bot

Copy link
Copy Markdown
Contributor

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@ExE-Boss
ExE Boss (ExE-Boss) marked this pull request as ready for review January 4, 2021 10:52

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems like a reasonable improvement that wouldn't break anything obvious because it leaves the originals behind as overloads. I did a quick sample of usage and Reflect is used sparingly across many prominent packages, so I think we'd notice problems after merging if there were going to be any.

However, I'd like to get the opinion of one other team member before merging, since lib changes nearly always have hidden gotches. Andrew Branch (@andrewbranch) or Ron Buckton (@rbuckton) can you give your opinion?

@sandersn
Nathan Shively-Sanders (sandersn) merged commit a123fc5 into microsoft:main Aug 9, 2022
@ExE-Boss
ExE Boss (ExE-Boss) deleted the lib/es2015/typed-reflect branch August 9, 2022 23:45
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants