Skip to content

Commit 7d4259b

Browse files
committed
Update tests
1 parent 652bb12 commit 7d4259b

File tree

1 file changed

+42
-31
lines changed

1 file changed

+42
-31
lines changed
Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,42 @@
1-
// Verify that inferences made *to* a type parameter in a union type are secondary
2-
// to inferences made directly to that type parameter
3-
4-
function f<T>(x: T, y: string|T): T {
5-
return x;
6-
}
7-
8-
var a1: number;
9-
var a1 = f(1, 2);
10-
var a2: number;
11-
var a2 = f(1, "hello");
12-
var a3: number;
13-
var a3 = f(1, a1 || "hello");
14-
var a4: any;
15-
var a4 = f(undefined, "abc");
16-
17-
function g<T>(value: [string, T]): T {
18-
return value[1];
19-
}
20-
21-
var b1: boolean;
22-
var b1 = g(["string", true]);
23-
24-
function h<T>(x: string|boolean|T): T {
25-
return typeof x === "string" || typeof x === "boolean" ? undefined : x;
26-
}
27-
28-
var c1: number;
29-
var c1 = h(5);
30-
var c2: string;
31-
var c2 = h("abc");
1+
// @strict: true
2+
3+
declare const b: boolean;
4+
declare const s: string;
5+
declare const sn: string | number;
6+
7+
declare function f1<T>(x: T, y: string | T): T;
8+
9+
const a1 = f1(1, 2); // 1 | 2
10+
const a2 = f1(1, "hello"); // 1
11+
const a3 = f1(1, sn); // number
12+
const a4 = f1(undefined, "abc"); // undefined
13+
const a5 = f1("foo", "bar"); // "foo"
14+
const a6 = f1(true, false); // boolean
15+
const a7 = f1("hello", 1); // Error
16+
17+
declare function f2<T>(value: [string, T]): T;
18+
19+
var b1 = f2(["string", true]); // boolean
20+
21+
declare function f3<T>(x: string | false | T): T;
22+
23+
const c1 = f3(5); // 5
24+
const c2 = f3(sn); // number
25+
const c3 = f3(true); // true
26+
const c4 = f3(b); // true
27+
const c5 = f3("abc"); // never
28+
29+
declare function f4<T>(x: string & T): T;
30+
31+
var d1 = f4("abc");
32+
var d2 = f4(s);
33+
var d3 = f4(42); // Error
34+
35+
// Repros from #32434
36+
37+
declare function foo<T>(x: T | Promise<T>): void;
38+
declare let x: false | Promise<true>;
39+
foo(x);
40+
41+
declare function bar<T>(x: T, y: string | T): T;
42+
const y = bar(1, 2);

0 commit comments

Comments
 (0)