Add regression tests
This commit is contained in:
parent
672d2144fa
commit
0dc42fea74
1 changed files with 25 additions and 0 deletions
25
tests/cases/compiler/controlFlowNullTypeAndLiteral.ts
Normal file
25
tests/cases/compiler/controlFlowNullTypeAndLiteral.ts
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
// @strict: true
|
||||||
|
|
||||||
|
// Repros from #23771
|
||||||
|
|
||||||
|
const myNull: null = null;
|
||||||
|
const objWithValMaybeNull: { val: number | null } = { val: 1 };
|
||||||
|
const addOne = function (num: number) {
|
||||||
|
return num + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (objWithValMaybeNull.val !== null)
|
||||||
|
addOne(objWithValMaybeNull.val);
|
||||||
|
if (objWithValMaybeNull.val !== myNull)
|
||||||
|
addOne(objWithValMaybeNull.val);
|
||||||
|
|
||||||
|
if (objWithValMaybeNull.val === null)
|
||||||
|
addOne(objWithValMaybeNull.val); // Error
|
||||||
|
if (objWithValMaybeNull.val === myNull)
|
||||||
|
addOne(objWithValMaybeNull.val); // Error
|
||||||
|
|
||||||
|
function f(x: number | null) {
|
||||||
|
if(x === myNull) {
|
||||||
|
const s: string = x; // Error
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue