Test:type inference from strings to keyof T succeeds

This commit is contained in:
Nathan Shively-Sanders
2017-10-16 13:35:12 -07:00
parent cfd97da680
commit cd1be1bbe3
4 changed files with 60 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
//// [inferObjectTypeFromStringLiteralToKeyof.ts]
declare function inference<T>(target: T, name: keyof T): void;
declare var two: "a" | "d";
inference({ a: 1, b: 2, c: 3, d(n) { return n } }, two);
//// [inferObjectTypeFromStringLiteralToKeyof.js]
inference({ a: 1, b: 2, c: 3, d: function (n) { return n; } }, two);

View File

@@ -0,0 +1,22 @@
=== tests/cases/compiler/inferObjectTypeFromStringLiteralToKeyof.ts ===
declare function inference<T>(target: T, name: keyof T): void;
>inference : Symbol(inference, Decl(inferObjectTypeFromStringLiteralToKeyof.ts, 0, 0))
>T : Symbol(T, Decl(inferObjectTypeFromStringLiteralToKeyof.ts, 0, 27))
>target : Symbol(target, Decl(inferObjectTypeFromStringLiteralToKeyof.ts, 0, 30))
>T : Symbol(T, Decl(inferObjectTypeFromStringLiteralToKeyof.ts, 0, 27))
>name : Symbol(name, Decl(inferObjectTypeFromStringLiteralToKeyof.ts, 0, 40))
>T : Symbol(T, Decl(inferObjectTypeFromStringLiteralToKeyof.ts, 0, 27))
declare var two: "a" | "d";
>two : Symbol(two, Decl(inferObjectTypeFromStringLiteralToKeyof.ts, 1, 11))
inference({ a: 1, b: 2, c: 3, d(n) { return n } }, two);
>inference : Symbol(inference, Decl(inferObjectTypeFromStringLiteralToKeyof.ts, 0, 0))
>a : Symbol(a, Decl(inferObjectTypeFromStringLiteralToKeyof.ts, 2, 11))
>b : Symbol(b, Decl(inferObjectTypeFromStringLiteralToKeyof.ts, 2, 17))
>c : Symbol(c, Decl(inferObjectTypeFromStringLiteralToKeyof.ts, 2, 23))
>d : Symbol(d, Decl(inferObjectTypeFromStringLiteralToKeyof.ts, 2, 29))
>n : Symbol(n, Decl(inferObjectTypeFromStringLiteralToKeyof.ts, 2, 32))
>n : Symbol(n, Decl(inferObjectTypeFromStringLiteralToKeyof.ts, 2, 32))
>two : Symbol(two, Decl(inferObjectTypeFromStringLiteralToKeyof.ts, 1, 11))

View File

@@ -0,0 +1,27 @@
=== tests/cases/compiler/inferObjectTypeFromStringLiteralToKeyof.ts ===
declare function inference<T>(target: T, name: keyof T): void;
>inference : <T>(target: T, name: keyof T) => void
>T : T
>target : T
>T : T
>name : keyof T
>T : T
declare var two: "a" | "d";
>two : "a" | "d"
inference({ a: 1, b: 2, c: 3, d(n) { return n } }, two);
>inference({ a: 1, b: 2, c: 3, d(n) { return n } }, two) : void
>inference : <T>(target: T, name: keyof T) => void
>{ a: 1, b: 2, c: 3, d(n) { return n } } : { a: number; b: number; c: number; d(n: any): any; }
>a : number
>1 : 1
>b : number
>2 : 2
>c : number
>3 : 3
>d : (n: any) => any
>n : any
>n : any
>two : "a" | "d"

View File

@@ -0,0 +1,3 @@
declare function inference<T>(target: T, name: keyof T): void;
declare var two: "a" | "d";
inference({ a: 1, b: 2, c: 3, d(n) { return n } }, two);