Add a testcase that fails when someone tried to make an Object.keys PR (#44368)

This commit is contained in:
Ryan Cavanaugh
2021-06-01 10:58:59 -07:00
committed by GitHub
parent 663b19fe4a
commit 4c018818c1
4 changed files with 53 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
//// [noObjectKeysToKeyofT.ts]
// Do not change Object.keys to return keyof T.
// The current return type (string[]) is intentional.
Object.keys({ a: 0 }).push("b");
// See also
// https://stackoverflow.com/questions/55012174/why-doesnt-object-keys-return-a-keyof-type-in-typescript
//// [noObjectKeysToKeyofT.js]
// Do not change Object.keys to return keyof T.
// The current return type (string[]) is intentional.
Object.keys({ a: 0 }).push("b");
// See also
// https://stackoverflow.com/questions/55012174/why-doesnt-object-keys-return-a-keyof-type-in-typescript

View File

@@ -0,0 +1,13 @@
=== tests/cases/compiler/noObjectKeysToKeyofT.ts ===
// Do not change Object.keys to return keyof T.
// The current return type (string[]) is intentional.
Object.keys({ a: 0 }).push("b");
>Object.keys({ a: 0 }).push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
>Object.keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --))
>Object : Symbol(Object, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>keys : Symbol(ObjectConstructor.keys, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --))
>a : Symbol(a, Decl(noObjectKeysToKeyofT.ts, 2, 13))
>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --))
// See also
// https://stackoverflow.com/questions/55012174/why-doesnt-object-keys-return-a-keyof-type-in-typescript

View File

@@ -0,0 +1,18 @@
=== tests/cases/compiler/noObjectKeysToKeyofT.ts ===
// Do not change Object.keys to return keyof T.
// The current return type (string[]) is intentional.
Object.keys({ a: 0 }).push("b");
>Object.keys({ a: 0 }).push("b") : number
>Object.keys({ a: 0 }).push : (...items: string[]) => number
>Object.keys({ a: 0 }) : string[]
>Object.keys : { (o: object): string[]; (o: {}): string[]; }
>Object : ObjectConstructor
>keys : { (o: object): string[]; (o: {}): string[]; }
>{ a: 0 } : { a: number; }
>a : number
>0 : 0
>push : (...items: string[]) => number
>"b" : "b"
// See also
// https://stackoverflow.com/questions/55012174/why-doesnt-object-keys-return-a-keyof-type-in-typescript

View File

@@ -0,0 +1,8 @@
// @target: es2016
// Do not change Object.keys to return keyof T.
// The current return type (string[]) is intentional.
Object.keys({ a: 0 }).push("b");
// See also
// https://stackoverflow.com/questions/55012174/why-doesnt-object-keys-return-a-keyof-type-in-typescript