Skip to content

Commit c4bad64

Browse files
committed
Accept new baselines
1 parent ae1add7 commit c4bad64

File tree

4 files changed

+369
-265
lines changed

4 files changed

+369
-265
lines changed
Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,50 @@
1-
tests/cases/conformance/types/typeRelationships/typeInference/unionTypeInference.ts(13,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'a3' must be of type 'number', but here has type 'string | number'.
2-
tests/cases/conformance/types/typeRelationships/typeInference/unionTypeInference.ts(31,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'c2' must be of type 'string', but here has type 'never'.
1+
tests/cases/conformance/types/typeRelationships/typeInference/unionTypeInference.ts(13,24): error TS2345: Argument of type '1' is not assignable to parameter of type 'string'.
2+
tests/cases/conformance/types/typeRelationships/typeInference/unionTypeInference.ts(31,13): error TS2345: Argument of type '42' is not assignable to parameter of type 'never'.
33

44

55
==== tests/cases/conformance/types/typeRelationships/typeInference/unionTypeInference.ts (2 errors) ====
6-
// Verify that inferences made *to* a type parameter in a union type are secondary
7-
// to inferences made directly to that type parameter
8-
9-
function f<T>(x: T, y: string|T): T {
10-
return x;
11-
}
12-
13-
var a1: number;
14-
var a1 = f(1, 2);
15-
var a2: number;
16-
var a2 = f(1, "hello");
17-
var a3: number;
18-
var a3 = f(1, a1 || "hello");
19-
~~
20-
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'a3' must be of type 'number', but here has type 'string | number'.
21-
!!! related TS6203 tests/cases/conformance/types/typeRelationships/typeInference/unionTypeInference.ts:12:5: 'a3' was also declared here.
22-
var a4: any;
23-
var a4 = f(undefined, "abc");
24-
25-
function g<T>(value: [string, T]): T {
26-
return value[1];
27-
}
28-
29-
var b1: boolean;
30-
var b1 = g(["string", true]);
31-
32-
function h<T>(x: string|boolean|T): T {
33-
return typeof x === "string" || typeof x === "boolean" ? undefined : x;
34-
}
35-
36-
var c1: number;
37-
var c1 = h(5);
38-
var c2: string;
39-
var c2 = h("abc");
40-
~~
41-
!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'c2' must be of type 'string', but here has type 'never'.
42-
!!! related TS6203 tests/cases/conformance/types/typeRelationships/typeInference/unionTypeInference.ts:30:5: 'c2' was also declared here.
6+
declare const b: boolean;
7+
declare const s: string;
8+
declare const sn: string | number;
9+
10+
declare function f1<T>(x: T, y: string | T): T;
11+
12+
const a1 = f1(1, 2); // 1 | 2
13+
const a2 = f1(1, "hello"); // 1
14+
const a3 = f1(1, sn); // number
15+
const a4 = f1(undefined, "abc"); // undefined
16+
const a5 = f1("foo", "bar"); // "foo"
17+
const a6 = f1(true, false); // boolean
18+
const a7 = f1("hello", 1); // Error
19+
~
20+
!!! error TS2345: Argument of type '1' is not assignable to parameter of type 'string'.
21+
22+
declare function f2<T>(value: [string, T]): T;
23+
24+
var b1 = f2(["string", true]); // boolean
25+
26+
declare function f3<T>(x: string | false | T): T;
27+
28+
const c1 = f3(5); // 5
29+
const c2 = f3(sn); // number
30+
const c3 = f3(true); // true
31+
const c4 = f3(b); // true
32+
const c5 = f3("abc"); // never
33+
34+
declare function f4<T>(x: string & T): T;
35+
36+
var d1 = f4("abc");
37+
var d2 = f4(s);
38+
var d3 = f4(42); // Error
39+
~~
40+
!!! error TS2345: Argument of type '42' is not assignable to parameter of type 'never'.
41+
42+
// Repros from #32434
43+
44+
declare function foo<T>(x: T | Promise<T>): void;
45+
declare let x: false | Promise<true>;
46+
foo(x);
47+
48+
declare function bar<T>(x: T, y: string | T): T;
49+
const y = bar(1, 2);
4350

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

3443

3544
//// [unionTypeInference.js]
36-
// Verify that inferences made *to* a type parameter in a union type are secondary
37-
// to inferences made directly to that type parameter
38-
function f(x, y) {
39-
return x;
40-
}
41-
var a1;
42-
var a1 = f(1, 2);
43-
var a2;
44-
var a2 = f(1, "hello");
45-
var a3;
46-
var a3 = f(1, a1 || "hello");
47-
var a4;
48-
var a4 = f(undefined, "abc");
49-
function g(value) {
50-
return value[1];
51-
}
52-
var b1;
53-
var b1 = g(["string", true]);
54-
function h(x) {
55-
return typeof x === "string" || typeof x === "boolean" ? undefined : x;
56-
}
57-
var c1;
58-
var c1 = h(5);
59-
var c2;
60-
var c2 = h("abc");
45+
"use strict";
46+
var a1 = f1(1, 2); // 1 | 2
47+
var a2 = f1(1, "hello"); // 1
48+
var a3 = f1(1, sn); // number
49+
var a4 = f1(undefined, "abc"); // undefined
50+
var a5 = f1("foo", "bar"); // "foo"
51+
var a6 = f1(true, false); // boolean
52+
var a7 = f1("hello", 1); // Error
53+
var b1 = f2(["string", true]); // boolean
54+
var c1 = f3(5); // 5
55+
var c2 = f3(sn); // number
56+
var c3 = f3(true); // true
57+
var c4 = f3(b); // true
58+
var c5 = f3("abc"); // never
59+
var d1 = f4("abc");
60+
var d2 = f4(s);
61+
var d3 = f4(42); // Error
62+
foo(x);
63+
var y = bar(1, 2);

0 commit comments

Comments
 (0)