mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Add regression test
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
//// [voidUndefinedReduction.ts]
|
||||
// Repro from #42786
|
||||
|
||||
function isDefined<T>(value: T | undefined | null | void): value is T {
|
||||
return value !== undefined && value !== null;
|
||||
}
|
||||
|
||||
declare const foo: string | undefined;
|
||||
|
||||
if (isDefined(foo)) {
|
||||
console.log(foo.toUpperCase());
|
||||
}
|
||||
|
||||
|
||||
//// [voidUndefinedReduction.js]
|
||||
"use strict";
|
||||
// Repro from #42786
|
||||
function isDefined(value) {
|
||||
return value !== undefined && value !== null;
|
||||
}
|
||||
if (isDefined(foo)) {
|
||||
console.log(foo.toUpperCase());
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
=== tests/cases/compiler/voidUndefinedReduction.ts ===
|
||||
// Repro from #42786
|
||||
|
||||
function isDefined<T>(value: T | undefined | null | void): value is T {
|
||||
>isDefined : Symbol(isDefined, Decl(voidUndefinedReduction.ts, 0, 0))
|
||||
>T : Symbol(T, Decl(voidUndefinedReduction.ts, 2, 19))
|
||||
>value : Symbol(value, Decl(voidUndefinedReduction.ts, 2, 22))
|
||||
>T : Symbol(T, Decl(voidUndefinedReduction.ts, 2, 19))
|
||||
>value : Symbol(value, Decl(voidUndefinedReduction.ts, 2, 22))
|
||||
>T : Symbol(T, Decl(voidUndefinedReduction.ts, 2, 19))
|
||||
|
||||
return value !== undefined && value !== null;
|
||||
>value : Symbol(value, Decl(voidUndefinedReduction.ts, 2, 22))
|
||||
>undefined : Symbol(undefined)
|
||||
>value : Symbol(value, Decl(voidUndefinedReduction.ts, 2, 22))
|
||||
}
|
||||
|
||||
declare const foo: string | undefined;
|
||||
>foo : Symbol(foo, Decl(voidUndefinedReduction.ts, 6, 13))
|
||||
|
||||
if (isDefined(foo)) {
|
||||
>isDefined : Symbol(isDefined, Decl(voidUndefinedReduction.ts, 0, 0))
|
||||
>foo : Symbol(foo, Decl(voidUndefinedReduction.ts, 6, 13))
|
||||
|
||||
console.log(foo.toUpperCase());
|
||||
>console.log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>console : Symbol(console, Decl(lib.dom.d.ts, --, --))
|
||||
>log : Symbol(Console.log, Decl(lib.dom.d.ts, --, --))
|
||||
>foo.toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
|
||||
>foo : Symbol(foo, Decl(voidUndefinedReduction.ts, 6, 13))
|
||||
>toUpperCase : Symbol(String.toUpperCase, Decl(lib.es5.d.ts, --, --))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
=== tests/cases/compiler/voidUndefinedReduction.ts ===
|
||||
// Repro from #42786
|
||||
|
||||
function isDefined<T>(value: T | undefined | null | void): value is T {
|
||||
>isDefined : <T>(value: T | undefined | null | void) => value is T
|
||||
>value : void | T | null | undefined
|
||||
>null : null
|
||||
|
||||
return value !== undefined && value !== null;
|
||||
>value !== undefined && value !== null : boolean
|
||||
>value !== undefined : boolean
|
||||
>value : void | T | null | undefined
|
||||
>undefined : undefined
|
||||
>value !== null : boolean
|
||||
>value : T | null
|
||||
>null : null
|
||||
}
|
||||
|
||||
declare const foo: string | undefined;
|
||||
>foo : string | undefined
|
||||
|
||||
if (isDefined(foo)) {
|
||||
>isDefined(foo) : boolean
|
||||
>isDefined : <T>(value: void | T | null | undefined) => value is T
|
||||
>foo : string | undefined
|
||||
|
||||
console.log(foo.toUpperCase());
|
||||
>console.log(foo.toUpperCase()) : void
|
||||
>console.log : (...data: any[]) => void
|
||||
>console : Console
|
||||
>log : (...data: any[]) => void
|
||||
>foo.toUpperCase() : string
|
||||
>foo.toUpperCase : () => string
|
||||
>foo : string
|
||||
>toUpperCase : () => string
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// @strict: true
|
||||
|
||||
// Repro from #42786
|
||||
|
||||
function isDefined<T>(value: T | undefined | null | void): value is T {
|
||||
return value !== undefined && value !== null;
|
||||
}
|
||||
|
||||
declare const foo: string | undefined;
|
||||
|
||||
if (isDefined(foo)) {
|
||||
console.log(foo.toUpperCase());
|
||||
}
|
||||
Reference in New Issue
Block a user