mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-04-17 13:48:46 -05:00
Add a testcase that fails when someone tried to make an Object.keys PR (#44368)
This commit is contained in:
14
tests/baselines/reference/noObjectKeysToKeyofT.js
Normal file
14
tests/baselines/reference/noObjectKeysToKeyofT.js
Normal 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
|
||||
13
tests/baselines/reference/noObjectKeysToKeyofT.symbols
Normal file
13
tests/baselines/reference/noObjectKeysToKeyofT.symbols
Normal 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
|
||||
18
tests/baselines/reference/noObjectKeysToKeyofT.types
Normal file
18
tests/baselines/reference/noObjectKeysToKeyofT.types
Normal 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
|
||||
8
tests/cases/compiler/noObjectKeysToKeyofT.ts
Normal file
8
tests/cases/compiler/noObjectKeysToKeyofT.ts
Normal 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
|
||||
Reference in New Issue
Block a user