Skip to content

Commit 00988ff

Browse files
committed
es2017.object
1 parent 5bdf063 commit 00988ff

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

build/replacement.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ export const replacement = new Map([
4040
["lib.es2015.promise.d.ts", new Set(["PromiseConstructor"])],
4141
["lib.es2015.proxy.d.ts", new Set(["ProxyHandler"])],
4242
["lib.es2015.reflect.d.ts", new Set(["Reflect"])],
43+
["lib.es2017.object.d.ts", new Set(["ObjectConstructor"])],
4344
]);

lib/lib.es2017.object.d.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/// <reference no-default-lib="true"/>
2+
3+
interface ObjectConstructor {
4+
/**
5+
* Returns an array of values of the enumerable properties of an object
6+
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
7+
*/
8+
values<T>(
9+
o: T
10+
): string | number extends keyof T
11+
? T[string | number][]
12+
: string extends keyof T
13+
? T[string][]
14+
: number extends keyof T
15+
? T[number][]
16+
: unknown[];
17+
18+
/**
19+
* Returns an array of key/values of the enumerable properties of an object
20+
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
21+
*/
22+
entries<T>(
23+
o: T
24+
): [
25+
string,
26+
string | number extends keyof T
27+
? T[string | number]
28+
: string extends keyof T
29+
? T[string]
30+
: number extends keyof T
31+
? T[number]
32+
: unknown
33+
][];
34+
35+
/**
36+
* Returns an object containing all own property descriptors of an object
37+
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
38+
*/
39+
getOwnPropertyDescriptors<T>(
40+
o: T
41+
): { [P in keyof T]: TypedPropertyDescriptor<T[P]> } & {
42+
[x: string]: PropertyDescriptor;
43+
};
44+
}

tests/es2017.object.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/// <reference path="../dist/lib/lib.es2017.d.ts" />
2+
3+
import { expectType } from "tsd";
4+
5+
{
6+
const obj1 = { foo: 123 };
7+
const values1 = Object.values(obj1);
8+
const entries1 = Object.entries(obj1);
9+
expectType<unknown[]>(values1);
10+
expectType<[string, unknown][]>(entries1);
11+
12+
const obj2: Record<string, number> = {};
13+
const values2 = Object.values(obj2);
14+
const entries2 = Object.entries(obj2);
15+
expectType<number[]>(values2);
16+
expectType<[string, number][]>(entries2);
17+
18+
const obj3 = ["foo", "bar", "baz"];
19+
const values3 = Object.values(obj3);
20+
const entries3 = Object.entries(obj3);
21+
expectType<string[]>(values3);
22+
expectType<[string, string][]>(entries3);
23+
}
24+
function test<T>(obj: T) {
25+
const values = Object.values(obj);
26+
expectType<unknown>(values[0]);
27+
28+
const entries = Object.entries(obj);
29+
expectType<string>(entries[0][0]);
30+
const v: unknown = entries[0][1];
31+
}

0 commit comments

Comments
 (0)