Skip to content

Commit

Permalink
feat: update Object.fromEntries types
Browse files Browse the repository at this point in the history
Added an optional generic type with PropertyKey as the default type for the object argument in Object.fromEntries. This makes the typing of this function “end-to-end”. For example, if [ “value1” | “value2”, string ][] is passed as an argument, the output value will be { [Key in “value1” | “value2”]: string }
  • Loading branch information
nezo32 authored Jan 29, 2025
1 parent 2d2264e commit d3471e2
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/es2019.object.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ interface ObjectConstructor {
* Returns an object created by key-value entries for properties and methods
* @param entries An iterable object that contains key-value entries for properties and methods.
*/
fromEntries<T = any>(entries: Iterable<readonly [PropertyKey, T]>): { [k: string]: T; };
fromEntries<T = any, K extends PropertyKey = PropertyKey>(entries: Iterable<readonly [K, T]>): { [Key in K]: T; };

/**
* Returns an object created by key-value entries for properties and methods
Expand Down

0 comments on commit d3471e2

Please sign in to comment.