Skip to content

Commit 6c2e62b

Browse files
committed
Add test case with temporary name
1 parent 2644fb0 commit 6c2e62b

File tree

5 files changed

+174
-0
lines changed

5 files changed

+174
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
tests/cases/compiler/issue49938.ts(12,15): error TS2345: Argument of type 'D | undefined' is not assignable to parameter of type 'B'.
2+
Type 'undefined' is not assignable to type 'B'.
3+
4+
5+
==== tests/cases/compiler/issue49938.ts (1 errors) ====
6+
function equal<T>(a: T, b: T) { }
7+
8+
let v = null!;
9+
10+
// Object types with common base types
11+
12+
type B = { foo: string }
13+
type D = { foo: string; bar: number }
14+
15+
// Error in 4.8 TS can't find common type ❌
16+
// 4.7 T was undefined | B
17+
equal(v as B, v as undefined | D)
18+
~~~~~~~~~~~~~~~~~~
19+
!!! error TS2345: Argument of type 'D | undefined' is not assignable to parameter of type 'B'.
20+
!!! error TS2345: Type 'undefined' is not assignable to type 'B'.
21+
22+
// ok T is B ✅
23+
equal(v as B, v as D)
24+
// ok T is B | undefined ✅
25+
equal(v as B, v as B | undefined)
26+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//// [issue49938.ts]
2+
function equal<T>(a: T, b: T) { }
3+
4+
let v = null!;
5+
6+
// Object types with common base types
7+
8+
type B = { foo: string }
9+
type D = { foo: string; bar: number }
10+
11+
// Error in 4.8 TS can't find common type ❌
12+
// 4.7 T was undefined | B
13+
equal(v as B, v as undefined | D)
14+
15+
// ok T is B ✅
16+
equal(v as B, v as D)
17+
// ok T is B | undefined ✅
18+
equal(v as B, v as B | undefined)
19+
20+
21+
//// [issue49938.js]
22+
"use strict";
23+
function equal(a, b) { }
24+
var v = null;
25+
// Error in 4.8 TS can't find common type ❌
26+
// 4.7 T was undefined | B
27+
equal(v, v);
28+
// ok T is B ✅
29+
equal(v, v);
30+
// ok T is B | undefined ✅
31+
equal(v, v);
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
=== tests/cases/compiler/issue49938.ts ===
2+
function equal<T>(a: T, b: T) { }
3+
>equal : Symbol(equal, Decl(issue49938.ts, 0, 0))
4+
>T : Symbol(T, Decl(issue49938.ts, 0, 15))
5+
>a : Symbol(a, Decl(issue49938.ts, 0, 18))
6+
>T : Symbol(T, Decl(issue49938.ts, 0, 15))
7+
>b : Symbol(b, Decl(issue49938.ts, 0, 23))
8+
>T : Symbol(T, Decl(issue49938.ts, 0, 15))
9+
10+
let v = null!;
11+
>v : Symbol(v, Decl(issue49938.ts, 2, 3))
12+
13+
// Object types with common base types
14+
15+
type B = { foo: string }
16+
>B : Symbol(B, Decl(issue49938.ts, 2, 14))
17+
>foo : Symbol(foo, Decl(issue49938.ts, 6, 10))
18+
19+
type D = { foo: string; bar: number }
20+
>D : Symbol(D, Decl(issue49938.ts, 6, 24))
21+
>foo : Symbol(foo, Decl(issue49938.ts, 7, 10))
22+
>bar : Symbol(bar, Decl(issue49938.ts, 7, 23))
23+
24+
// Error in 4.8 TS can't find common type ❌
25+
// 4.7 T was undefined | B
26+
equal(v as B, v as undefined | D)
27+
>equal : Symbol(equal, Decl(issue49938.ts, 0, 0))
28+
>v : Symbol(v, Decl(issue49938.ts, 2, 3))
29+
>B : Symbol(B, Decl(issue49938.ts, 2, 14))
30+
>v : Symbol(v, Decl(issue49938.ts, 2, 3))
31+
>D : Symbol(D, Decl(issue49938.ts, 6, 24))
32+
33+
// ok T is B ✅
34+
equal(v as B, v as D)
35+
>equal : Symbol(equal, Decl(issue49938.ts, 0, 0))
36+
>v : Symbol(v, Decl(issue49938.ts, 2, 3))
37+
>B : Symbol(B, Decl(issue49938.ts, 2, 14))
38+
>v : Symbol(v, Decl(issue49938.ts, 2, 3))
39+
>D : Symbol(D, Decl(issue49938.ts, 6, 24))
40+
41+
// ok T is B | undefined ✅
42+
equal(v as B, v as B | undefined)
43+
>equal : Symbol(equal, Decl(issue49938.ts, 0, 0))
44+
>v : Symbol(v, Decl(issue49938.ts, 2, 3))
45+
>B : Symbol(B, Decl(issue49938.ts, 2, 14))
46+
>v : Symbol(v, Decl(issue49938.ts, 2, 3))
47+
>B : Symbol(B, Decl(issue49938.ts, 2, 14))
48+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
=== tests/cases/compiler/issue49938.ts ===
2+
function equal<T>(a: T, b: T) { }
3+
>equal : <T>(a: T, b: T) => void
4+
>a : T
5+
>b : T
6+
7+
let v = null!;
8+
>v : never
9+
>null! : never
10+
>null : null
11+
12+
// Object types with common base types
13+
14+
type B = { foo: string }
15+
>B : { foo: string; }
16+
>foo : string
17+
18+
type D = { foo: string; bar: number }
19+
>D : { foo: string; bar: number; }
20+
>foo : string
21+
>bar : number
22+
23+
// Error in 4.8 TS can't find common type ❌
24+
// 4.7 T was undefined | B
25+
equal(v as B, v as undefined | D)
26+
>equal(v as B, v as undefined | D) : void
27+
>equal : <T>(a: T, b: T) => void
28+
>v as B : B
29+
>v : never
30+
>v as undefined | D : D | undefined
31+
>v : never
32+
33+
// ok T is B ✅
34+
equal(v as B, v as D)
35+
>equal(v as B, v as D) : void
36+
>equal : <T>(a: T, b: T) => void
37+
>v as B : B
38+
>v : never
39+
>v as D : D
40+
>v : never
41+
42+
// ok T is B | undefined ✅
43+
equal(v as B, v as B | undefined)
44+
>equal(v as B, v as B | undefined) : void
45+
>equal : <T>(a: T, b: T) => void
46+
>v as B : B
47+
>v : never
48+
>v as B | undefined : B | undefined
49+
>v : never
50+

tests/cases/compiler/issue49938.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// @strict: true
2+
3+
function equal<T>(a: T, b: T) { }
4+
5+
let v = null!;
6+
7+
// Object types with common base types
8+
9+
type B = { foo: string }
10+
type D = { foo: string; bar: number }
11+
12+
// Error in 4.8 TS can't find common type ❌
13+
// 4.7 T was undefined | B
14+
equal(v as B, v as undefined | D)
15+
16+
// ok T is B ✅
17+
equal(v as B, v as D)
18+
// ok T is B | undefined ✅
19+
equal(v as B, v as B | undefined)

0 commit comments

Comments
 (0)