From 0dc42fea743f5ca50a667a6e604fa85832492df0 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 30 Apr 2018 10:43:55 -0700 Subject: [PATCH] Add regression tests --- .../compiler/controlFlowNullTypeAndLiteral.ts | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/cases/compiler/controlFlowNullTypeAndLiteral.ts diff --git a/tests/cases/compiler/controlFlowNullTypeAndLiteral.ts b/tests/cases/compiler/controlFlowNullTypeAndLiteral.ts new file mode 100644 index 00000000000..ee66f441f14 --- /dev/null +++ b/tests/cases/compiler/controlFlowNullTypeAndLiteral.ts @@ -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 + } +}