Skip to content

Commit 4c01881

Browse files
Add a testcase that fails when someone tried to make an Object.keys PR (microsoft#44368)
1 parent 663b19f commit 4c01881

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [noObjectKeysToKeyofT.ts]
2+
// Do not change Object.keys to return keyof T.
3+
// The current return type (string[]) is intentional.
4+
Object.keys({ a: 0 }).push("b");
5+
6+
// See also
7+
// https://stackoverflow.com/questions/55012174/why-doesnt-object-keys-return-a-keyof-type-in-typescript
8+
9+
//// [noObjectKeysToKeyofT.js]
10+
// Do not change Object.keys to return keyof T.
11+
// The current return type (string[]) is intentional.
12+
Object.keys({ a: 0 }).push("b");
13+
// See also
14+
// https://stackoverflow.com/questions/55012174/why-doesnt-object-keys-return-a-keyof-type-in-typescript
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/noObjectKeysToKeyofT.ts ===
2+
// Do not change Object.keys to return keyof T.
3+
// The current return type (string[]) is intentional.
4+
Object.keys({ a: 0 }).push("b");
5+
>Object.keys({ a: 0 }).push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
6+
>Object.keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --))
7+
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
8+
>keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --))
9+
>a : Symbol(a, Decl(noObjectKeysToKeyofT.ts, 2, 13))
10+
>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
11+
12+
// See also
13+
// https://stackoverflow.com/questions/55012174/why-doesnt-object-keys-return-a-keyof-type-in-typescript
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== tests/cases/compiler/noObjectKeysToKeyofT.ts ===
2+
// Do not change Object.keys to return keyof T.
3+
// The current return type (string[]) is intentional.
4+
Object.keys({ a: 0 }).push("b");
5+
>Object.keys({ a: 0 }).push("b") : number
6+
>Object.keys({ a: 0 }).push : (...items: string[]) => number
7+
>Object.keys({ a: 0 }) : string[]
8+
>Object.keys : { (o: object): string[]; (o: {}): string[]; }
9+
>Object : ObjectConstructor
10+
>keys : { (o: object): string[]; (o: {}): string[]; }
11+
>{ a: 0 } : { a: number; }
12+
>a : number
13+
>0 : 0
14+
>push : (...items: string[]) => number
15+
>"b" : "b"
16+
17+
// See also
18+
// https://stackoverflow.com/questions/55012174/why-doesnt-object-keys-return-a-keyof-type-in-typescript
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @target: es2016
2+
3+
// Do not change Object.keys to return keyof T.
4+
// The current return type (string[]) is intentional.
5+
Object.keys({ a: 0 }).push("b");
6+
7+
// See also
8+
// https://stackoverflow.com/questions/55012174/why-doesnt-object-keys-return-a-keyof-type-in-typescript

0 commit comments

Comments
 (0)