-
Notifications
You must be signed in to change notification settings - Fork 12.9k
add support of fromEntries #26149
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 support of fromEntries #26149
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/// <reference lib="es2018" /> | ||
/// <reference lib="esnext.asynciterable" /> | ||
/// <reference lib="esnext.array" /> | ||
/// <reference lib="esnext.object" /> | ||
/// <reference lib="esnext.symbol" /> | ||
/// <reference lib="esnext.intl" /> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
interface ObjectConstructor { | ||
/** | ||
* Returns an object from an array of properties key/values | ||
* @param entries Array that contains the properties key and value. | ||
*/ | ||
fromEntries<T>(entries: ArrayLike<[string, T]> | Iterable<[string, T]>): Record<string, T>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to support tuple types but not sure the compiler is clever enough to deal with that without having to define 200 overloads fromEntries<K1 extends string, V1>(entries: [[K1, V1]]): { [K1]: V1 }
fromEntries<K1 extends string, V1, K2 extends string, V2>(entries: [[K1, V1], [K2, V2]]): { [K1]: V1; [K2]: V2 }
// ... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was nice if typescript had any way to declare types mapping from tuple to object There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a real use case for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a use case for that :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Bnaya can you share a realistic code snippet where object literal syntax doesn't work but fixed-length There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drive-by comment: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😸 The more comprehensive version is:
Current TypeScript treats tuples as assignable to objects with numeric literal keys. Using |
||
|
||
/** | ||
* Returns an object from an array of properties key/values | ||
* @param entries Array that contains the properties key and value. | ||
*/ | ||
fromEntries(entries: ArrayLike<[string, any]> | Iterable<[string, any]>): Record<string, any>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
(Edit: Or replace it with |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RyanCavanaugh the new file will need to be added to the setup of the VS SDK. you will need to run
VS\scripts\distributeLibFiles.bat
to update the setup.