Skip to content

Commit e7b6601

Browse files
committed
Add regression test
1 parent 6b487a6 commit e7b6601

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//// [voidUndefinedReduction.ts]
2+
// Repro from #42786
3+
4+
function isDefined<T>(value: T | undefined | null | void): value is T {
5+
return value !== undefined && value !== null;
6+
}
7+
8+
declare const foo: string | undefined;
9+
10+
if (isDefined(foo)) {
11+
console.log(foo.toUpperCase());
12+
}
13+
14+
15+
//// [voidUndefinedReduction.js]
16+
"use strict";
17+
// Repro from #42786
18+
function isDefined(value) {
19+
return value !== undefined && value !== null;
20+
}
21+
if (isDefined(foo)) {
22+
console.log(foo.toUpperCase());
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
=== tests/cases/compiler/voidUndefinedReduction.ts ===
2+
// Repro from #42786
3+
4+
function isDefined<T>(value: T | undefined | null | void): value is T {
5+
>isDefined : Symbol(isDefined, Decl(voidUndefinedReduction.ts, 0, 0))
6+
>T : Symbol(T, Decl(voidUndefinedReduction.ts, 2, 19))
7+
>value : Symbol(value, Decl(voidUndefinedReduction.ts, 2, 22))
8+
>T : Symbol(T, Decl(voidUndefinedReduction.ts, 2, 19))
9+
>value : Symbol(value, Decl(voidUndefinedReduction.ts, 2, 22))
10+
>T : Symbol(T, Decl(voidUndefinedReduction.ts, 2, 19))
11+
12+
return value !== undefined && value !== null;
13+
>value : Symbol(value, Decl(voidUndefinedReduction.ts, 2, 22))
14+
>undefined : Symbol(undefined)
15+
>value : Symbol(value, Decl(voidUndefinedReduction.ts, 2, 22))
16+
}
17+
18+
declare const foo: string | undefined;
19+
>foo : Symbol(foo, Decl(voidUndefinedReduction.ts, 6, 13))
20+
21+
if (isDefined(foo)) {
22+
>isDefined : Symbol(isDefined, Decl(voidUndefinedReduction.ts, 0, 0))
23+
>foo : Symbol(foo, Decl(voidUndefinedReduction.ts, 6, 13))
24+
25+
console.log(foo.toUpperCase());
26+
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
27+
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
28+
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
29+
>foo.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
30+
>foo : Symbol(foo, Decl(voidUndefinedReduction.ts, 6, 13))
31+
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
32+
}
33+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
=== tests/cases/compiler/voidUndefinedReduction.ts ===
2+
// Repro from #42786
3+
4+
function isDefined<T>(value: T | undefined | null | void): value is T {
5+
>isDefined : <T>(value: T | undefined | null | void) => value is T
6+
>value : void | T | null | undefined
7+
>null : null
8+
9+
return value !== undefined && value !== null;
10+
>value !== undefined && value !== null : boolean
11+
>value !== undefined : boolean
12+
>value : void | T | null | undefined
13+
>undefined : undefined
14+
>value !== null : boolean
15+
>value : T | null
16+
>null : null
17+
}
18+
19+
declare const foo: string | undefined;
20+
>foo : string | undefined
21+
22+
if (isDefined(foo)) {
23+
>isDefined(foo) : boolean
24+
>isDefined : <T>(value: void | T | null | undefined) => value is T
25+
>foo : string | undefined
26+
27+
console.log(foo.toUpperCase());
28+
>console.log(foo.toUpperCase()) : void
29+
>console.log : (...data: any[]) => void
30+
>console : Console
31+
>log : (...data: any[]) => void
32+
>foo.toUpperCase() : string
33+
>foo.toUpperCase : () => string
34+
>foo : string
35+
>toUpperCase : () => string
36+
}
37+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @strict: true
2+
3+
// Repro from #42786
4+
5+
function isDefined<T>(value: T | undefined | null | void): value is T {
6+
return value !== undefined && value !== null;
7+
}
8+
9+
declare const foo: string | undefined;
10+
11+
if (isDefined(foo)) {
12+
console.log(foo.toUpperCase());
13+
}

0 commit comments

Comments
 (0)