Update tests

This commit is contained in:
Anders Hejlsberg 2019-07-17 14:57:26 -07:00
parent 652bb1277c
commit 7d4259ba9f

View File

@ -1,31 +1,42 @@
// Verify that inferences made *to* a type parameter in a union type are secondary
// to inferences made directly to that type parameter
// @strict: true
function f<T>(x: T, y: string|T): T {
return x;
}
declare const b: boolean;
declare const s: string;
declare const sn: string | number;
var a1: number;
var a1 = f(1, 2);
var a2: number;
var a2 = f(1, "hello");
var a3: number;
var a3 = f(1, a1 || "hello");
var a4: any;
var a4 = f(undefined, "abc");
declare function f1<T>(x: T, y: string | T): T;
function g<T>(value: [string, T]): T {
return value[1];
}
const a1 = f1(1, 2); // 1 | 2
const a2 = f1(1, "hello"); // 1
const a3 = f1(1, sn); // number
const a4 = f1(undefined, "abc"); // undefined
const a5 = f1("foo", "bar"); // "foo"
const a6 = f1(true, false); // boolean
const a7 = f1("hello", 1); // Error
var b1: boolean;
var b1 = g(["string", true]);
declare function f2<T>(value: [string, T]): T;
function h<T>(x: string|boolean|T): T {
return typeof x === "string" || typeof x === "boolean" ? undefined : x;
}
var b1 = f2(["string", true]); // boolean
var c1: number;
var c1 = h(5);
var c2: string;
var c2 = h("abc");
declare function f3<T>(x: string | false | T): T;
const c1 = f3(5); // 5
const c2 = f3(sn); // number
const c3 = f3(true); // true
const c4 = f3(b); // true
const c5 = f3("abc"); // never
declare function f4<T>(x: string & T): T;
var d1 = f4("abc");
var d2 = f4(s);
var d3 = f4(42); // Error
// Repros from #32434
declare function foo<T>(x: T | Promise<T>): void;
declare let x: false | Promise<true>;
foo(x);
declare function bar<T>(x: T, y: string | T): T;
const y = bar(1, 2);