From eb06af19013e0265895d446b0b9f177dcf3541fa Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 17 Sep 2018 13:01:53 -0700 Subject: [PATCH] Add tests --- .../controlFlow/controlFlowTruthiness.ts | 27 +++++++++++++++++++ .../keyof/keyofAndIndexedAccessErrors.ts | 6 +++++ 2 files changed, 33 insertions(+) diff --git a/tests/cases/conformance/controlFlow/controlFlowTruthiness.ts b/tests/cases/conformance/controlFlow/controlFlowTruthiness.ts index ba1947da13b..0245f9bfea0 100644 --- a/tests/cases/conformance/controlFlow/controlFlowTruthiness.ts +++ b/tests/cases/conformance/controlFlow/controlFlowTruthiness.ts @@ -68,3 +68,30 @@ function f6() { y; // string | undefined } } + +function f7(x: {}) { + if (x) { + x; // {} + } + else { + x; // {} + } +} + +function f8(x: T) { + if (x) { + x; // {} + } + else { + x; // {} + } +} + +function f9(x: T) { + if (x) { + x; // {} + } + else { + x; // never + } +} \ No newline at end of file diff --git a/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts b/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts index bb2b9d95117..3660ff418e8 100644 --- a/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts +++ b/tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts @@ -116,3 +116,9 @@ function f3, U extends T, J extends K>( tk = uj; uj = tk; // error } + +// The constraint of 'keyof T' is 'keyof T' +function f4(k: keyof T) { + k = 42; // error + k = "hello"; // error +}