94 lines
3.7 KiB
Text
94 lines
3.7 KiB
Text
=== 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))
|
|
|