mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Test:type inference from strings to keyof T succeeds
This commit is contained in:
@@ -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);
|
||||
@@ -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))
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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);
|
||||
Reference in New Issue
Block a user