TypeScript/tests/baselines/reference/genericCallWithObjectTypeArgsAndStringIndexer.types

107 lines
5.7 KiB
Plaintext
Raw Normal View History

2014-08-15 23:33:16 +02:00
=== tests/cases/conformance/types/typeRelationships/typeInference/genericCallWithObjectTypeArgsAndStringIndexer.ts ===
// Type inference infers from indexers in target type, no errors expected
function foo<T>(x: T) {
2015-04-13 23:01:57 +02:00
>foo : <T>(x: T) => T, Symbol(foo, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 0, 0))
>T : T, Symbol(T, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 2, 13))
>x : T, Symbol(x, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 2, 16))
>T : T, Symbol(T, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 2, 13))
2014-08-15 23:33:16 +02:00
return x;
2015-04-13 23:01:57 +02:00
>x : T, Symbol(x, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 2, 16))
2014-08-15 23:33:16 +02:00
}
var a: { [x: string]: Date };
2015-04-13 23:01:57 +02:00
>a : { [x: string]: Date; }, Symbol(a, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 6, 3))
>x : string, Symbol(x, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 6, 10))
>Date : Date, Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11))
2014-08-15 23:33:16 +02:00
var r = foo(a);
2015-04-13 23:01:57 +02:00
>r : { [x: string]: Date; }, Symbol(r, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 7, 3))
2014-08-15 23:33:16 +02:00
>foo(a) : { [x: string]: Date; }
2015-04-13 23:01:57 +02:00
>foo : <T>(x: T) => T, Symbol(foo, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 0, 0))
>a : { [x: string]: Date; }, Symbol(a, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 6, 3))
2014-08-15 23:33:16 +02:00
function other<T>(arg: T) {
2015-04-13 23:01:57 +02:00
>other : <T>(arg: T) => void, Symbol(other, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 7, 15))
>T : T, Symbol(T, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 9, 15))
>arg : T, Symbol(arg, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 9, 18))
>T : T, Symbol(T, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 9, 15))
2014-08-15 23:33:16 +02:00
var b: { [x: string]: T };
2015-04-13 23:01:57 +02:00
>b : { [x: string]: T; }, Symbol(b, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 10, 7))
>x : string, Symbol(x, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 10, 14))
>T : T, Symbol(T, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 9, 15))
2014-08-15 23:33:16 +02:00
var r2 = foo(b); // T
2015-04-13 23:01:57 +02:00
>r2 : { [x: string]: T; }, Symbol(r2, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 11, 7))
2014-08-15 23:33:16 +02:00
>foo(b) : { [x: string]: T; }
2015-04-13 23:01:57 +02:00
>foo : <T>(x: T) => T, Symbol(foo, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 0, 0))
>b : { [x: string]: T; }, Symbol(b, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 10, 7))
2014-08-15 23:33:16 +02:00
}
function other2<T extends Date>(arg: T) {
2015-04-13 23:01:57 +02:00
>other2 : <T extends Date>(arg: T) => void, Symbol(other2, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 12, 1))
>T : T, Symbol(T, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 14, 16))
>Date : Date, Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11))
>arg : T, Symbol(arg, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 14, 32))
>T : T, Symbol(T, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 14, 16))
2014-08-15 23:33:16 +02:00
var b: { [x: string]: T };
2015-04-13 23:01:57 +02:00
>b : { [x: string]: T; }, Symbol(b, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 15, 7))
>x : string, Symbol(x, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 15, 14))
>T : T, Symbol(T, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 14, 16))
2014-08-15 23:33:16 +02:00
var r2 = foo(b);
2015-04-13 23:01:57 +02:00
>r2 : { [x: string]: T; }, Symbol(r2, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 16, 7))
2014-08-15 23:33:16 +02:00
>foo(b) : { [x: string]: T; }
2015-04-13 23:01:57 +02:00
>foo : <T>(x: T) => T, Symbol(foo, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 0, 0))
>b : { [x: string]: T; }, Symbol(b, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 15, 7))
2014-08-15 23:33:16 +02:00
var d: Date = r2['hm']; // ok
2015-04-13 23:01:57 +02:00
>d : Date, Symbol(d, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 17, 7))
>Date : Date, Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11))
2014-08-15 23:33:16 +02:00
>r2['hm'] : T
2015-04-13 23:01:57 +02:00
>r2 : { [x: string]: T; }, Symbol(r2, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 16, 7))
2015-04-13 21:36:11 +02:00
>'hm' : string
2014-08-15 23:33:16 +02:00
}
function other3<T extends Date, U extends Date>(arg: T) {
2015-04-13 23:01:57 +02:00
>other3 : <T extends Date, U extends Date>(arg: T) => void, Symbol(other3, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 18, 1))
>T : T, Symbol(T, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 20, 16))
>Date : Date, Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11))
>U : U, Symbol(U, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 20, 31))
>Date : Date, Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11))
>arg : T, Symbol(arg, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 20, 48))
>T : T, Symbol(T, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 20, 16))
2014-08-15 23:33:16 +02:00
var b: { [x: string]: T };
2015-04-13 23:01:57 +02:00
>b : { [x: string]: T; }, Symbol(b, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 21, 7))
>x : string, Symbol(x, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 21, 14))
>T : T, Symbol(T, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 20, 16))
2014-08-15 23:33:16 +02:00
var r2 = foo(b);
2015-04-13 23:01:57 +02:00
>r2 : { [x: string]: T; }, Symbol(r2, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 22, 7))
2014-08-15 23:33:16 +02:00
>foo(b) : { [x: string]: T; }
2015-04-13 23:01:57 +02:00
>foo : <T>(x: T) => T, Symbol(foo, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 0, 0))
>b : { [x: string]: T; }, Symbol(b, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 21, 7))
2014-08-15 23:33:16 +02:00
var d: Date = r2['hm']; // ok
2015-04-13 23:01:57 +02:00
>d : Date, Symbol(d, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 23, 7))
>Date : Date, Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11))
2014-08-15 23:33:16 +02:00
>r2['hm'] : T
2015-04-13 23:01:57 +02:00
>r2 : { [x: string]: T; }, Symbol(r2, Decl(genericCallWithObjectTypeArgsAndStringIndexer.ts, 22, 7))
2015-04-13 21:36:11 +02:00
>'hm' : string
2014-08-15 23:33:16 +02:00
// BUG 821629
//var u: U = r2['hm']; // ok
}
//function other3<T extends U, U extends Date>(arg: T) {
// var b: { [x: string]: T };
// var r2 = foo(b);
// var d: Date = r2['hm']; // ok
// // BUG 821629
// //var u: U = r2['hm']; // ok
//}