Skip to content

Commit

Permalink
Accept new baselines
Browse files Browse the repository at this point in the history
  • Loading branch information
ahejlsberg committed May 15, 2022
1 parent 29edef1 commit 39326d7
Show file tree
Hide file tree
Showing 17 changed files with 128 additions and 54 deletions.
2 changes: 1 addition & 1 deletion tests/baselines/reference/assertionTypePredicates1.types
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ function f01(x: unknown) {
>undefined : undefined
>typeof x === "string" : boolean
>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>x : unknown
>x : {} | null
>"string" : "string"

x; // string | undefined
Expand Down
16 changes: 8 additions & 8 deletions tests/baselines/reference/controlFlowGenericTypes.types
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function f1<T extends string | undefined>(x: T, y: { a: T }, z: [T]): string {
>x : T

x;
>x : T
>x : T & {}

x.length;
>x.length : number
Expand Down Expand Up @@ -44,13 +44,13 @@ function f1<T extends string | undefined>(x: T, y: { a: T }, z: [T]): string {

z[0].length;
>z[0].length : number
>z[0] : string
>z[0] : T & {}
>z : [T]
>0 : 0
>length : number

return z[0];
>z[0] : string
>z[0] : T & {}
>z : [T]
>0 : 0
}
Expand All @@ -67,7 +67,7 @@ function f2<T>(x: Extract<T, string | undefined> | null): string {
>x : Extract<T, string | undefined> | null

x;
>x : Extract<T, string | undefined>
>x : Extract<T, string | undefined> & {}

x.length;
>x.length : number
Expand Down Expand Up @@ -404,11 +404,11 @@ function fx1<T, K extends keyof T>(obj: T, key: K) {
>key : K

const x2 = obj && obj[key];
>x2 : T[K]
>obj && obj[key] : T[K]
>obj : T
>obj[key] : T[K]
>x2 : (T & {})[K]
>obj && obj[key] : (T & {})[K]
>obj : T
>obj[key] : (T & {})[K]
>obj : T & {}
>key : K
}

Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/controlFlowTruthiness.types
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ function f8<T>(x: T) {
>x : T

x; // {}
>x : T
>x : T & {}
}
else {
x; // {}
Expand Down
14 changes: 7 additions & 7 deletions tests/baselines/reference/controlFlowTypeofObject.types
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function f1(x: unknown) {
if (typeof x === 'object') {
>typeof x === 'object' : boolean
>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>x : unknown
>x : {}
>'object' : "object"

obj(x);
Expand All @@ -40,7 +40,7 @@ function f2(x: unknown) {
if (typeof x === 'object') {
>typeof x === 'object' : boolean
>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>x : unknown
>x : {} | undefined
>'object' : "object"

obj(x);
Expand All @@ -64,7 +64,7 @@ function f3(x: unknown) {
if (typeof x === 'object') {
>typeof x === 'object' : boolean
>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>x : unknown
>x : {}
>'object' : "object"

obj(x);
Expand All @@ -88,7 +88,7 @@ function f4(x: unknown) {
if (typeof x === 'object') {
>typeof x === 'object' : boolean
>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>x : unknown
>x : {}
>'object' : "object"

obj(x);
Expand Down Expand Up @@ -126,7 +126,7 @@ function f5(x: unknown) {
if (typeof x === 'object') {
>typeof x === 'object' : boolean
>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>x : unknown
>x : {} | undefined
>'object' : "object"

obj(x);
Expand All @@ -150,12 +150,12 @@ function f6(x: unknown) {
}
else {
x;
>x : unknown
>x : {} | undefined

if (typeof x === 'object') {
>typeof x === 'object' : boolean
>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>x : unknown
>x : {} | undefined
>'object' : "object"

obj(x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ tests/cases/compiler/inDoesNotOperateOnPrimitiveTypes.ts(23,12): error TS2361: T
tests/cases/compiler/inDoesNotOperateOnPrimitiveTypes.ts(27,12): error TS2361: The right-hand side of an 'in' expression must not be a primitive.
tests/cases/compiler/inDoesNotOperateOnPrimitiveTypes.ts(34,12): error TS2361: The right-hand side of an 'in' expression must not be a primitive.
tests/cases/compiler/inDoesNotOperateOnPrimitiveTypes.ts(53,14): error TS2361: The right-hand side of an 'in' expression must not be a primitive.
tests/cases/compiler/inDoesNotOperateOnPrimitiveTypes.ts(55,18): error TS2361: The right-hand side of an 'in' expression must not be a primitive.
tests/cases/compiler/inDoesNotOperateOnPrimitiveTypes.ts(60,12): error TS2361: The right-hand side of an 'in' expression must not be a primitive.
tests/cases/compiler/inDoesNotOperateOnPrimitiveTypes.ts(64,12): error TS2361: The right-hand side of an 'in' expression must not be a primitive.


==== tests/cases/compiler/inDoesNotOperateOnPrimitiveTypes.ts (8 errors) ====
==== tests/cases/compiler/inDoesNotOperateOnPrimitiveTypes.ts (7 errors) ====
const validHasKey = <T extends object>(
thing: T,
key: string,
Expand Down Expand Up @@ -74,8 +73,6 @@ tests/cases/compiler/inDoesNotOperateOnPrimitiveTypes.ts(64,12): error TS2361: T
!!! error TS2361: The right-hand side of an 'in' expression must not be a primitive.
if (typeof p === "object") {
"key" in p;
~
!!! error TS2361: The right-hand side of an 'in' expression must not be a primitive.
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function union5<T extends object | string, U extends object | number>(p: T | U)
"key" in p;
>"key" in p : boolean
>"key" : "key"
>p : T | U
>p : (T & object) | (U & object)
}
}

Expand Down
77 changes: 77 additions & 0 deletions tests/baselines/reference/mappedTypes4.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
tests/cases/conformance/types/mapped/mappedTypes4.ts(11,23): error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type '(T & null) | (T & object)'.


==== tests/cases/conformance/types/mapped/mappedTypes4.ts (1 errors) ====
type Box<T> = {
};

type Boxified<T> = {
[P in keyof T]: Box<T[P]>;
};

function boxify<T>(obj: T): Boxified<T> {
if (typeof obj === "object") {
let result = {} as Boxified<T>;
for (let k in obj) {
~~~
!!! error TS2407: The right-hand side of a 'for...in' statement must be of type 'any', an object type or a type parameter, but here has type '(T & null) | (T & object)'.
result[k] = { value: obj[k] };
}
return result;
}
return <any>obj;
}

type A = { a: string };
type B = { b: string };
type C = { c: string };

function f1(x: A | B | C | undefined) {
return boxify(x);
}

type T00 = Partial<A | B | C>;
type T01 = Readonly<A | B | C | null | undefined>;
type T02 = Boxified<A | B[] | C | string>
type T03 = Readonly<string | number | boolean | null | undefined | void>;
type T04 = Boxified<string | number | boolean | null | undefined | void>;
type T05 = Partial<"hello" | "world" | 42>;

type BoxifiedWithSentinel<T, U> = {
[P in keyof T]: Box<T[P]> | U;
}

type T10 = BoxifiedWithSentinel<A | B | C, null>;
type T11 = BoxifiedWithSentinel<A | B | C, undefined>;
type T12 = BoxifiedWithSentinel<string, undefined>;

type DeepReadonly<T> = {
readonly [P in keyof T]: DeepReadonly<T[P]>;
};

type Foo = {
x: number;
y: { a: string, b: number };
z: boolean;
};

type DeepReadonlyFoo = {
readonly x: number;
readonly y: { readonly a: string, readonly b: number };
readonly z: boolean;
};

var x1: DeepReadonly<Foo>;
var x1: DeepReadonlyFoo;

// Repro from #13232

type Z = { a: number };
type Clone<T> = {
[P in keyof (T & {})]: T[P];
};
type M = Clone<Z>; // M should be { a: number }

var z1: Z;
var z1: Clone<Z>;

12 changes: 6 additions & 6 deletions tests/baselines/reference/mappedTypes4.types
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ function boxify<T>(obj: T): Boxified<T> {

for (let k in obj) {
>k : Extract<keyof T, string>
>obj : T
>obj : (T & null) | (T & object)

result[k] = { value: obj[k] };
>result[k] = { value: obj[k] } : { value: T[Extract<keyof T, string>]; }
>result[k] = { value: obj[k] } : { value: ((T & null) | (T & object))[Extract<keyof T, string>]; }
>result[k] : Boxified<T>[Extract<keyof T, string>]
>result : Boxified<T>
>k : Extract<keyof T, string>
>{ value: obj[k] } : { value: T[Extract<keyof T, string>]; }
>value : T[Extract<keyof T, string>]
>obj[k] : T[Extract<keyof T, string>]
>obj : T
>{ value: obj[k] } : { value: ((T & null) | (T & object))[Extract<keyof T, string>]; }
>value : ((T & null) | (T & object))[Extract<keyof T, string>]
>obj[k] : ((T & null) | (T & object))[Extract<keyof T, string>]
>obj : (T & null) | (T & object)
>k : Extract<keyof T, string>
}
return result;
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/narrowByEquality.types
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ if (xUnknown == null) {

} else {
xUnknown
>xUnknown : unknown
>xUnknown : {}
}

if (xUnknown != null) {
Expand All @@ -153,7 +153,7 @@ if (xUnknown != null) {
>null : null

xUnknown;
>xUnknown : unknown
>xUnknown : {}

} else {
xUnknown;
Expand Down
18 changes: 9 additions & 9 deletions tests/baselines/reference/narrowingByTypeofInSwitch.types
Original file line number Diff line number Diff line change
Expand Up @@ -552,14 +552,14 @@ function multipleGenericFuse<X extends L | number, Y extends R | number>(xy: X |

case 'function': return [xy, 1];
>'function' : "function"
>[xy, 1] : [X, 1]
>xy : X
>[xy, 1] : [X & Function, 1]
>xy : X & Function
>1 : 1

case 'object': return [xy, 'two'];
>'object' : "object"
>[xy, 'two'] : [Y, string]
>xy : Y
>[xy, 'two'] : [Y & object, string]
>xy : Y & object
>'two' : "two"

case 'number': return [xy]
Expand Down Expand Up @@ -843,7 +843,7 @@ function narrowingNarrows(x: {} | undefined) {
case 'object': const _: {} = x; return;
>'object' : "object"
>_ : {}
>x : {}
>x : object

case 'string': assertString(x); return;
>'string' : "string"
Expand Down Expand Up @@ -1092,14 +1092,14 @@ function multipleGenericFuseWithBoth<X extends L | number, Y extends R | number>

case `function`: return [xy, 1];
>`function` : "function"
>[xy, 1] : [X, 1]
>xy : X
>[xy, 1] : [X & Function, 1]
>xy : X & Function
>1 : 1

case 'object': return [xy, 'two'];
>'object' : "object"
>[xy, 'two'] : [Y, string]
>xy : Y
>[xy, 'two'] : [Y & object, string]
>xy : Y & object
>'two' : "two"

case `number`: return [xy]
Expand Down
12 changes: 6 additions & 6 deletions tests/baselines/reference/narrowingTruthyObject.types
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function foo(x: unknown, b: boolean) {
>x : unknown
>typeof x === 'object' : boolean
>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>x : unknown
>x : {}
>'object' : "object"

x.toString();
Expand All @@ -51,7 +51,7 @@ function foo(x: unknown, b: boolean) {
>x : unknown
>typeof x === 'object' : boolean
>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>x : unknown
>x : {}
>'object' : "object"

x.toString();
Expand All @@ -67,7 +67,7 @@ function foo(x: unknown, b: boolean) {
>b : boolean
>typeof x === 'object' : boolean
>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>x : unknown
>x : {}
>'object' : "object"

x.toString();
Expand All @@ -85,7 +85,7 @@ function foo(x: unknown, b: boolean) {
>b : true
>typeof x === 'object' : boolean
>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>x : unknown
>x : {}
>'object' : "object"

x.toString();
Expand All @@ -107,7 +107,7 @@ function foo(x: unknown, b: boolean) {
>b : true
>typeof x === 'object' : boolean
>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>x : unknown
>x : {}
>'object' : "object"

x.toString();
Expand All @@ -130,7 +130,7 @@ function f1(x: unknown): any {
>x : unknown
>typeof x === 'object' : boolean
>typeof x : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>x : unknown
>x : {}
>'object' : "object"
>x.hasOwnProperty('x') : boolean
>x.hasOwnProperty : (v: PropertyKey) => boolean
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/narrowingTypeofFunction.types
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function f2<T>(x: (T & F) | T & string) {
>"function" : "function"

x;
>x : (T & F) | (T & string)
>x : T & F
}
else {
x;
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/strictOptionalProperties1.types
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ function expectNotUndefined<T>(value: Undefinable<T>): T {
>'value is undefined' : "value is undefined"
}
return value;
>value : T
>value : T & ({} | null)
}

interface Bar {
Expand Down
Loading

0 comments on commit 39326d7

Please sign in to comment.