Accept new baselines

This commit is contained in:
Anders Hejlsberg
2018-09-17 13:02:01 -07:00
parent eb06af1901
commit 17080eb58f
7 changed files with 205 additions and 2 deletions
@@ -67,7 +67,33 @@ function f6() {
y; // string | undefined
}
}
function f7(x: {}) {
if (x) {
x; // {}
}
else {
x; // {}
}
}
function f8<T>(x: T) {
if (x) {
x; // {}
}
else {
x; // {}
}
}
function f9<T extends object>(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
}
}
@@ -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<T>(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<T extends object>(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))
}
}
@@ -157,3 +157,50 @@ function f6() {
}
}
function f7(x: {}) {
>f7 : (x: {}) => void
>x : {}
if (x) {
>x : {}
x; // {}
>x : {}
}
else {
x; // {}
>x : {}
}
}
function f8<T>(x: T) {
>f8 : <T>(x: T) => void
>x : T
if (x) {
>x : T
x; // {}
>x : T
}
else {
x; // {}
>x : T
}
}
function f9<T extends object>(x: T) {
>f9 : <T extends object>(x: T) => void
>x : T
if (x) {
>x : T
x; // {}
>x : T
}
else {
x; // never
>x : never
}
}
@@ -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<T extends { [K in keyof T]: string }>(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'.
}
@@ -117,6 +117,12 @@ function f3<T, K extends Extract<keyof T, string>, U extends T, J extends K>(
tk = uj;
uj = tk; // error
}
// The constraint of 'keyof T' is 'keyof T'
function f4<T extends { [K in keyof T]: string }>(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
}
@@ -412,3 +412,19 @@ function f3<T, K extends Extract<keyof T, string>, U extends T, J extends K>(
>tk : Symbol(tk, Decl(keyofAndIndexedAccessErrors.ts, 99, 15))
}
// The constraint of 'keyof T' is 'keyof T'
function f4<T extends { [K in keyof T]: string }>(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))
}
@@ -396,3 +396,19 @@ function f3<T, K extends Extract<keyof T, string>, U extends T, J extends K>(
>tk : T[K]
}
// The constraint of 'keyof T' is 'keyof T'
function f4<T extends { [K in keyof T]: string }>(k: keyof T) {
>f4 : <T extends { [K in keyof T]: string; }>(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"
}