We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Object.fromEntries
1 parent 818a2d7 commit f8afdd7Copy full SHA for f8afdd7
typings/object.d.ts
@@ -9,4 +9,24 @@ type ObjectKeys<T> = T extends object
9
10
interface ObjectConstructor {
11
keys<T>(o: T): ObjectKeys<T>;
12
+
13
+ fromEntries<
14
+ V extends PropertyKey,
15
+ T extends [readonly [V, any]] | Array<readonly [V, any]>,
16
+ >(
17
+ entries: T,
18
+ ): Flatten<UnionToIntersection<FromEntries<T[number]>>>;
19
}
20
21
+// From https://github.com/microsoft/TypeScript/issues/35745#issuecomment-566932289
22
+type UnionToIntersection<T> = (T extends T ? (p: T) => void : never) extends (
23
+ p: infer U,
24
+) => void
25
+ ? U
26
+ : never;
27
+type FromEntries<T extends readonly [PropertyKey, any]> = T extends T
28
+ ? Record<T[0], T[1]>
29
30
+type Flatten<T> = object & {
31
+ [P in keyof T]: T[P];
32
+};
0 commit comments