From 17080eb58f27a75cc2bb8e21308b7990d3751849 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 17 Sep 2018 13:02:01 -0700 Subject: [PATCH] Accept new baselines --- .../reference/controlFlowTruthiness.js | 52 ++++++++++++++++++- .../reference/controlFlowTruthiness.symbols | 51 ++++++++++++++++++ .../reference/controlFlowTruthiness.types | 47 +++++++++++++++++ .../keyofAndIndexedAccessErrors.errors.txt | 14 ++++- .../reference/keyofAndIndexedAccessErrors.js | 11 ++++ .../keyofAndIndexedAccessErrors.symbols | 16 ++++++ .../keyofAndIndexedAccessErrors.types | 16 ++++++ 7 files changed, 205 insertions(+), 2 deletions(-) diff --git a/tests/baselines/reference/controlFlowTruthiness.js b/tests/baselines/reference/controlFlowTruthiness.js index b57befbd641..a841619ace5 100644 --- a/tests/baselines/reference/controlFlowTruthiness.js +++ b/tests/baselines/reference/controlFlowTruthiness.js @@ -67,7 +67,33 @@ 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 + } +} //// [controlFlowTruthiness.js] function f1() { @@ -131,3 +157,27 @@ function f6() { y; // string | undefined } } +function f7(x) { + if (x) { + x; // {} + } + else { + x; // {} + } +} +function f8(x) { + if (x) { + x; // {} + } + else { + x; // {} + } +} +function f9(x) { + if (x) { + x; // {} + } + else { + x; // never + } +} diff --git a/tests/baselines/reference/controlFlowTruthiness.symbols b/tests/baselines/reference/controlFlowTruthiness.symbols index 72dd304f810..098a81e5164 100644 --- a/tests/baselines/reference/controlFlowTruthiness.symbols +++ b/tests/baselines/reference/controlFlowTruthiness.symbols @@ -140,3 +140,54 @@ function f6() { } } +function f7(x: {}) { +>f7 : Symbol(f7, Decl(controlFlowTruthiness.ts, 67, 1)) +>x : Symbol(x, Decl(controlFlowTruthiness.ts, 69, 12)) + + if (x) { +>x : Symbol(x, Decl(controlFlowTruthiness.ts, 69, 12)) + + x; // {} +>x : Symbol(x, Decl(controlFlowTruthiness.ts, 69, 12)) + } + else { + x; // {} +>x : Symbol(x, Decl(controlFlowTruthiness.ts, 69, 12)) + } +} + +function f8(x: T) { +>f8 : Symbol(f8, Decl(controlFlowTruthiness.ts, 76, 1)) +>T : Symbol(T, Decl(controlFlowTruthiness.ts, 78, 12)) +>x : Symbol(x, Decl(controlFlowTruthiness.ts, 78, 15)) +>T : Symbol(T, Decl(controlFlowTruthiness.ts, 78, 12)) + + if (x) { +>x : Symbol(x, Decl(controlFlowTruthiness.ts, 78, 15)) + + x; // {} +>x : Symbol(x, Decl(controlFlowTruthiness.ts, 78, 15)) + } + else { + x; // {} +>x : Symbol(x, Decl(controlFlowTruthiness.ts, 78, 15)) + } +} + +function f9(x: T) { +>f9 : Symbol(f9, Decl(controlFlowTruthiness.ts, 85, 1)) +>T : Symbol(T, Decl(controlFlowTruthiness.ts, 87, 12)) +>x : Symbol(x, Decl(controlFlowTruthiness.ts, 87, 30)) +>T : Symbol(T, Decl(controlFlowTruthiness.ts, 87, 12)) + + if (x) { +>x : Symbol(x, Decl(controlFlowTruthiness.ts, 87, 30)) + + x; // {} +>x : Symbol(x, Decl(controlFlowTruthiness.ts, 87, 30)) + } + else { + x; // never +>x : Symbol(x, Decl(controlFlowTruthiness.ts, 87, 30)) + } +} diff --git a/tests/baselines/reference/controlFlowTruthiness.types b/tests/baselines/reference/controlFlowTruthiness.types index 225f6d0e7e2..454d094f406 100644 --- a/tests/baselines/reference/controlFlowTruthiness.types +++ b/tests/baselines/reference/controlFlowTruthiness.types @@ -157,3 +157,50 @@ function f6() { } } +function f7(x: {}) { +>f7 : (x: {}) => void +>x : {} + + if (x) { +>x : {} + + x; // {} +>x : {} + } + else { + x; // {} +>x : {} + } +} + +function f8(x: T) { +>f8 : (x: T) => void +>x : T + + if (x) { +>x : T + + x; // {} +>x : T + } + else { + x; // {} +>x : T + } +} + +function f9(x: T) { +>f9 : (x: T) => void +>x : T + + if (x) { +>x : T + + x; // {} +>x : T + } + else { + x; // never +>x : never + } +} diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt b/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt index dd5cbe050a9..4053189aea3 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.errors.txt @@ -61,9 +61,11 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(114,5): error Type 'string' is not assignable to type 'J'. tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(117,5): error TS2322: Type 'T[K]' is not assignable to type 'U[J]'. Type 'T' is not assignable to type 'U'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(122,5): error TS2322: Type '42' is not assignable to type 'keyof T'. +tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(123,5): error TS2322: Type '"hello"' is not assignable to type 'keyof T'. -==== tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts (36 errors) ==== +==== tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts (38 errors) ==== class Shape { name: string; width: number; @@ -281,4 +283,14 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(117,5): error !!! error TS2322: Type 'T[K]' is not assignable to type 'U[J]'. !!! error TS2322: Type 'T' is not assignable to type 'U'. } + + // The constraint of 'keyof T' is 'keyof T' + function f4(k: keyof T) { + k = 42; // error + ~ +!!! error TS2322: Type '42' is not assignable to type 'keyof T'. + k = "hello"; // error + ~ +!!! error TS2322: Type '"hello"' is not assignable to type 'keyof T'. + } \ No newline at end of file diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.js b/tests/baselines/reference/keyofAndIndexedAccessErrors.js index c64f4df5331..a3124ce4c71 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.js +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.js @@ -117,6 +117,12 @@ 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 +} //// [keyofAndIndexedAccessErrors.js] @@ -178,3 +184,8 @@ function f3(t, k, tk, u, j, uk, tj, uj) { tk = uj; uj = tk; // error } +// The constraint of 'keyof T' is 'keyof T' +function f4(k) { + k = 42; // error + k = "hello"; // error +} diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols b/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols index f5c5f41dddf..72739eb76d7 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.symbols @@ -412,3 +412,19 @@ function f3, U extends T, J extends K>( >tk : Symbol(tk, Decl(keyofAndIndexedAccessErrors.ts, 99, 15)) } +// The constraint of 'keyof T' is 'keyof T' +function f4(k: keyof T) { +>f4 : Symbol(f4, Decl(keyofAndIndexedAccessErrors.ts, 117, 1)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 120, 12)) +>K : Symbol(K, Decl(keyofAndIndexedAccessErrors.ts, 120, 25)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 120, 12)) +>k : Symbol(k, Decl(keyofAndIndexedAccessErrors.ts, 120, 50)) +>T : Symbol(T, Decl(keyofAndIndexedAccessErrors.ts, 120, 12)) + + k = 42; // error +>k : Symbol(k, Decl(keyofAndIndexedAccessErrors.ts, 120, 50)) + + k = "hello"; // error +>k : Symbol(k, Decl(keyofAndIndexedAccessErrors.ts, 120, 50)) +} + diff --git a/tests/baselines/reference/keyofAndIndexedAccessErrors.types b/tests/baselines/reference/keyofAndIndexedAccessErrors.types index c15f5ebb6ef..e5f8b6ee8e3 100644 --- a/tests/baselines/reference/keyofAndIndexedAccessErrors.types +++ b/tests/baselines/reference/keyofAndIndexedAccessErrors.types @@ -396,3 +396,19 @@ function f3, U extends T, J extends K>( >tk : T[K] } +// The constraint of 'keyof T' is 'keyof T' +function f4(k: keyof T) { +>f4 : (k: keyof T) => void +>k : keyof T + + k = 42; // error +>k = 42 : 42 +>k : keyof T +>42 : 42 + + k = "hello"; // error +>k = "hello" : "hello" +>k : keyof T +>"hello" : "hello" +} +