1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
=== tests/cases/conformance/types/typeRelationships/typeInference/unionTypeInference.ts ===
// Verify that inferences made *to* a type parameter in a union type are secondary
// to inferences made directly to that type parameter
function f<T>(x: T, y: string|T): T {
>f : Symbol(f, Decl(unionTypeInference.ts, 0, 0))
>T : Symbol(T, Decl(unionTypeInference.ts, 3, 11))
>x : Symbol(x, Decl(unionTypeInference.ts, 3, 14))
>T : Symbol(T, Decl(unionTypeInference.ts, 3, 11))
>y : Symbol(y, Decl(unionTypeInference.ts, 3, 19))
>T : Symbol(T, Decl(unionTypeInference.ts, 3, 11))
>T : Symbol(T, Decl(unionTypeInference.ts, 3, 11))
return x;
>x : Symbol(x, Decl(unionTypeInference.ts, 3, 14))
}
var a1: number;
>a1 : Symbol(a1, Decl(unionTypeInference.ts, 7, 3), Decl(unionTypeInference.ts, 8, 3))
var a1 = f(1, 2);
>a1 : Symbol(a1, Decl(unionTypeInference.ts, 7, 3), Decl(unionTypeInference.ts, 8, 3))
>f : Symbol(f, Decl(unionTypeInference.ts, 0, 0))
var a2: number;
>a2 : Symbol(a2, Decl(unionTypeInference.ts, 9, 3), Decl(unionTypeInference.ts, 10, 3))
var a2 = f(1, "hello");
>a2 : Symbol(a2, Decl(unionTypeInference.ts, 9, 3), Decl(unionTypeInference.ts, 10, 3))
>f : Symbol(f, Decl(unionTypeInference.ts, 0, 0))
var a3: number;
>a3 : Symbol(a3, Decl(unionTypeInference.ts, 11, 3), Decl(unionTypeInference.ts, 12, 3))
var a3 = f(1, a1 || "hello");
>a3 : Symbol(a3, Decl(unionTypeInference.ts, 11, 3), Decl(unionTypeInference.ts, 12, 3))
>f : Symbol(f, Decl(unionTypeInference.ts, 0, 0))
>a1 : Symbol(a1, Decl(unionTypeInference.ts, 7, 3), Decl(unionTypeInference.ts, 8, 3))
var a4: any;
>a4 : Symbol(a4, Decl(unionTypeInference.ts, 13, 3), Decl(unionTypeInference.ts, 14, 3))
var a4 = f(undefined, "abc");
>a4 : Symbol(a4, Decl(unionTypeInference.ts, 13, 3), Decl(unionTypeInference.ts, 14, 3))
>f : Symbol(f, Decl(unionTypeInference.ts, 0, 0))
>undefined : Symbol(undefined)
function g<T>(value: [string, T]): T {
>g : Symbol(g, Decl(unionTypeInference.ts, 14, 29))
>T : Symbol(T, Decl(unionTypeInference.ts, 16, 11))
>value : Symbol(value, Decl(unionTypeInference.ts, 16, 14))
>T : Symbol(T, Decl(unionTypeInference.ts, 16, 11))
>T : Symbol(T, Decl(unionTypeInference.ts, 16, 11))
return value[1];
>value : Symbol(value, Decl(unionTypeInference.ts, 16, 14))
>1 : Symbol(1)
}
var b1: boolean;
>b1 : Symbol(b1, Decl(unionTypeInference.ts, 20, 3), Decl(unionTypeInference.ts, 21, 3))
var b1 = g(["string", true]);
>b1 : Symbol(b1, Decl(unionTypeInference.ts, 20, 3), Decl(unionTypeInference.ts, 21, 3))
>g : Symbol(g, Decl(unionTypeInference.ts, 14, 29))
function h<T>(x: string|boolean|T): T {
>h : Symbol(h, Decl(unionTypeInference.ts, 21, 29))
>T : Symbol(T, Decl(unionTypeInference.ts, 23, 11))
>x : Symbol(x, Decl(unionTypeInference.ts, 23, 14))
>T : Symbol(T, Decl(unionTypeInference.ts, 23, 11))
>T : Symbol(T, Decl(unionTypeInference.ts, 23, 11))
return typeof x === "string" || typeof x === "boolean" ? undefined : x;
>x : Symbol(x, Decl(unionTypeInference.ts, 23, 14))
>x : Symbol(x, Decl(unionTypeInference.ts, 23, 14))
>undefined : Symbol(undefined)
>x : Symbol(x, Decl(unionTypeInference.ts, 23, 14))
}
var c1: number;
>c1 : Symbol(c1, Decl(unionTypeInference.ts, 27, 3), Decl(unionTypeInference.ts, 28, 3))
var c1 = h(5);
>c1 : Symbol(c1, Decl(unionTypeInference.ts, 27, 3), Decl(unionTypeInference.ts, 28, 3))
>h : Symbol(h, Decl(unionTypeInference.ts, 21, 29))
var c2: string;
>c2 : Symbol(c2, Decl(unionTypeInference.ts, 29, 3), Decl(unionTypeInference.ts, 30, 3))
var c2 = h("abc");
>c2 : Symbol(c2, Decl(unionTypeInference.ts, 29, 3), Decl(unionTypeInference.ts, 30, 3))
>h : Symbol(h, Decl(unionTypeInference.ts, 21, 29))
|