From 451f65332c40fe93ccd703f075dfb85f46d162dc Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 19 Feb 2019 07:02:37 -1000 Subject: [PATCH 01/19] Improve contextual typing by generic rest parameter --- src/compiler/checker.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3bd089aff6f..6711d56fe30 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10669,9 +10669,9 @@ namespace ts { return !!(mapper).typeParameters; } - function cloneTypeMapper(mapper: TypeMapper): TypeMapper { + function cloneTypeMapper(mapper: TypeMapper, extraFlags: InferenceFlags = 0): TypeMapper { return mapper && isInferenceContext(mapper) ? - createInferenceContext(mapper.typeParameters, mapper.signature, mapper.flags | InferenceFlags.NoDefault, mapper.compareTypes, mapper.inferences) : + createInferenceContext(mapper.typeParameters, mapper.signature, mapper.flags | extraFlags, mapper.compareTypes, mapper.inferences) : mapper; } @@ -19984,7 +19984,7 @@ namespace ts { // We clone the contextual mapper to avoid disturbing a resolution in progress for an // outer call expression. Effectively we just want a snapshot of whatever has been // inferred for any outer call expression so far. - const instantiatedType = instantiateType(contextualType, cloneTypeMapper(getContextualMapper(node))); + const instantiatedType = instantiateType(contextualType, cloneTypeMapper(getContextualMapper(node), InferenceFlags.NoDefault)); // If the contextual type is a generic function type with a single call signature, we // instantiate the type with its own type parameters and type arguments. This ensures that // the type parameters are not erased to type any during type inference such that they can @@ -21652,6 +21652,17 @@ namespace ts { } } } + const restType = getEffectiveRestType(context); + if (restType && restType.flags & TypeFlags.TypeParameter) { + // The contextual signature has a generic rest parameter. We first instantiate the contextual + // signature (without fixing type parameters) and assign types to contextually typed parameters. + const instantiatedContext = instantiateSignature(context, cloneTypeMapper(mapper)); + assignContextualParameterTypes(signature, instantiatedContext); + // We then infer from a tuple type representing the parameters that correspond to the contextual + // rest parameter. + const restPos = getParameterCount(context) - 1; + inferTypes((mapper).inferences, getRestTypeAtPosition(signature, restPos), restType); + } } function assignContextualParameterTypes(signature: Signature, context: Signature) { From f19191b0811a7ad8245b4603aa98eba507fcbc3f Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 19 Feb 2019 07:02:50 -1000 Subject: [PATCH 02/19] Add tests --- .../types/rest/restTuplesFromContextualTypes.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/cases/conformance/types/rest/restTuplesFromContextualTypes.ts b/tests/cases/conformance/types/rest/restTuplesFromContextualTypes.ts index d5623a000a2..85421a7697b 100644 --- a/tests/cases/conformance/types/rest/restTuplesFromContextualTypes.ts +++ b/tests/cases/conformance/types/rest/restTuplesFromContextualTypes.ts @@ -59,6 +59,21 @@ function f4(t: T) { f((a, b, ...x) => {}); } +declare function f5(f: (...args: T) => U): (...args: T) => U; + +let g0 = f5(() => "hello"); +let g1 = f5((x, y) => 42); +let g2 = f5((x: number, y) => 42); +let g3 = f5((x: number, y: number) => x + y); +let g4 = f5((...args) => true); + +declare function pipe(f: (...args: A) => B, g: (x: B) => C): (...args: A) => C; + +let g5 = pipe(() => true, b => 42); +let g6 = pipe(x => "hello", s => s.length); +let g7 = pipe((x, y) => 42, x => "" + x); +let g8 = pipe((x: number, y: string) => 42, x => "" + x); + // Repro from #25288 declare var tuple: [number, string]; From d0cb0471897d6d357f162da10e871c00b5633a60 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 19 Feb 2019 07:04:31 -1000 Subject: [PATCH 03/19] Accept new baselines --- .../restTuplesFromContextualTypes.errors.txt | 15 ++ .../restTuplesFromContextualTypes.js | 41 +++++ .../restTuplesFromContextualTypes.symbols | 146 ++++++++++++++---- .../restTuplesFromContextualTypes.types | 109 +++++++++++++ 4 files changed, 282 insertions(+), 29 deletions(-) diff --git a/tests/baselines/reference/restTuplesFromContextualTypes.errors.txt b/tests/baselines/reference/restTuplesFromContextualTypes.errors.txt index 2b94b57f462..5f2c299735b 100644 --- a/tests/baselines/reference/restTuplesFromContextualTypes.errors.txt +++ b/tests/baselines/reference/restTuplesFromContextualTypes.errors.txt @@ -68,6 +68,21 @@ tests/cases/conformance/types/rest/restTuplesFromContextualTypes.ts(56,7): error !!! error TS2345: Property '0' is missing in type 'any[]' but required in type '[T[0], ...T[number][]]'. } + declare function f5(f: (...args: T) => U): (...args: T) => U; + + let g0 = f5(() => "hello"); + let g1 = f5((x, y) => 42); + let g2 = f5((x: number, y) => 42); + let g3 = f5((x: number, y: number) => x + y); + let g4 = f5((...args) => true); + + declare function pipe(f: (...args: A) => B, g: (x: B) => C): (...args: A) => C; + + let g5 = pipe(() => true, b => 42); + let g6 = pipe(x => "hello", s => s.length); + let g7 = pipe((x, y) => 42, x => "" + x); + let g8 = pipe((x: number, y: string) => 42, x => "" + x); + // Repro from #25288 declare var tuple: [number, string]; diff --git a/tests/baselines/reference/restTuplesFromContextualTypes.js b/tests/baselines/reference/restTuplesFromContextualTypes.js index 34e75fcea6e..affe55603bf 100644 --- a/tests/baselines/reference/restTuplesFromContextualTypes.js +++ b/tests/baselines/reference/restTuplesFromContextualTypes.js @@ -57,6 +57,21 @@ function f4(t: T) { f((a, b, ...x) => {}); } +declare function f5(f: (...args: T) => U): (...args: T) => U; + +let g0 = f5(() => "hello"); +let g1 = f5((x, y) => 42); +let g2 = f5((x: number, y) => 42); +let g3 = f5((x: number, y: number) => x + y); +let g4 = f5((...args) => true); + +declare function pipe(f: (...args: A) => B, g: (x: B) => C): (...args: A) => C; + +let g5 = pipe(() => true, b => 42); +let g6 = pipe(x => "hello", s => s.length); +let g7 = pipe((x, y) => 42, x => "" + x); +let g8 = pipe((x: number, y: string) => 42, x => "" + x); + // Repro from #25288 declare var tuple: [number, string]; @@ -275,6 +290,21 @@ function f4(t) { } }); } +var g0 = f5(function () { return "hello"; }); +var g1 = f5(function (x, y) { return 42; }); +var g2 = f5(function (x, y) { return 42; }); +var g3 = f5(function (x, y) { return x + y; }); +var g4 = f5(function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + return true; +}); +var g5 = pipe(function () { return true; }, function (b) { return 42; }); +var g6 = pipe(function (x) { return "hello"; }, function (s) { return s.length; }); +var g7 = pipe(function (x, y) { return 42; }, function (x) { return "" + x; }); +var g8 = pipe(function (x, y) { return 42; }, function (x) { return "" + x; }); (function foo(a, b) { }.apply(void 0, tuple)); (function foo() { var rest = []; @@ -309,6 +339,17 @@ declare function f2(cb: (...args: typeof t2) => void): void; declare const t3: [boolean, ...string[]]; declare function f3(cb: (x: number, ...args: typeof t3) => void): void; declare function f4(t: T): void; +declare function f5(f: (...args: T) => U): (...args: T) => U; +declare let g0: () => string; +declare let g1: (x: any, y: any) => number; +declare let g2: (x: number, y: any) => number; +declare let g3: (x: number, y: number) => number; +declare let g4: (...args: any[]) => boolean; +declare function pipe(f: (...args: A) => B, g: (x: B) => C): (...args: A) => C; +declare let g5: () => number; +declare let g6: (x: any) => number; +declare let g7: (x: any, y: any) => string; +declare let g8: (x: number, y: string) => string; declare var tuple: [number, string]; declare function take(cb: (a: number, b: string) => void): void; declare type ArgsUnion = [number, string] | [number, Error]; diff --git a/tests/baselines/reference/restTuplesFromContextualTypes.symbols b/tests/baselines/reference/restTuplesFromContextualTypes.symbols index c58e8cabcae..8cde9f48907 100644 --- a/tests/baselines/reference/restTuplesFromContextualTypes.symbols +++ b/tests/baselines/reference/restTuplesFromContextualTypes.symbols @@ -238,67 +238,155 @@ function f4(t: T) { >x : Symbol(x, Decl(restTuplesFromContextualTypes.ts, 55, 12)) } +declare function f5(f: (...args: T) => U): (...args: T) => U; +>f5 : Symbol(f5, Decl(restTuplesFromContextualTypes.ts, 56, 1)) +>T : Symbol(T, Decl(restTuplesFromContextualTypes.ts, 58, 20)) +>U : Symbol(U, Decl(restTuplesFromContextualTypes.ts, 58, 36)) +>f : Symbol(f, Decl(restTuplesFromContextualTypes.ts, 58, 40)) +>args : Symbol(args, Decl(restTuplesFromContextualTypes.ts, 58, 44)) +>T : Symbol(T, Decl(restTuplesFromContextualTypes.ts, 58, 20)) +>U : Symbol(U, Decl(restTuplesFromContextualTypes.ts, 58, 36)) +>args : Symbol(args, Decl(restTuplesFromContextualTypes.ts, 58, 64)) +>T : Symbol(T, Decl(restTuplesFromContextualTypes.ts, 58, 20)) +>U : Symbol(U, Decl(restTuplesFromContextualTypes.ts, 58, 36)) + +let g0 = f5(() => "hello"); +>g0 : Symbol(g0, Decl(restTuplesFromContextualTypes.ts, 60, 3)) +>f5 : Symbol(f5, Decl(restTuplesFromContextualTypes.ts, 56, 1)) + +let g1 = f5((x, y) => 42); +>g1 : Symbol(g1, Decl(restTuplesFromContextualTypes.ts, 61, 3)) +>f5 : Symbol(f5, Decl(restTuplesFromContextualTypes.ts, 56, 1)) +>x : Symbol(x, Decl(restTuplesFromContextualTypes.ts, 61, 13)) +>y : Symbol(y, Decl(restTuplesFromContextualTypes.ts, 61, 15)) + +let g2 = f5((x: number, y) => 42); +>g2 : Symbol(g2, Decl(restTuplesFromContextualTypes.ts, 62, 3)) +>f5 : Symbol(f5, Decl(restTuplesFromContextualTypes.ts, 56, 1)) +>x : Symbol(x, Decl(restTuplesFromContextualTypes.ts, 62, 13)) +>y : Symbol(y, Decl(restTuplesFromContextualTypes.ts, 62, 23)) + +let g3 = f5((x: number, y: number) => x + y); +>g3 : Symbol(g3, Decl(restTuplesFromContextualTypes.ts, 63, 3)) +>f5 : Symbol(f5, Decl(restTuplesFromContextualTypes.ts, 56, 1)) +>x : Symbol(x, Decl(restTuplesFromContextualTypes.ts, 63, 13)) +>y : Symbol(y, Decl(restTuplesFromContextualTypes.ts, 63, 23)) +>x : Symbol(x, Decl(restTuplesFromContextualTypes.ts, 63, 13)) +>y : Symbol(y, Decl(restTuplesFromContextualTypes.ts, 63, 23)) + +let g4 = f5((...args) => true); +>g4 : Symbol(g4, Decl(restTuplesFromContextualTypes.ts, 64, 3)) +>f5 : Symbol(f5, Decl(restTuplesFromContextualTypes.ts, 56, 1)) +>args : Symbol(args, Decl(restTuplesFromContextualTypes.ts, 64, 13)) + +declare function pipe(f: (...args: A) => B, g: (x: B) => C): (...args: A) => C; +>pipe : Symbol(pipe, Decl(restTuplesFromContextualTypes.ts, 64, 31)) +>A : Symbol(A, Decl(restTuplesFromContextualTypes.ts, 66, 22)) +>B : Symbol(B, Decl(restTuplesFromContextualTypes.ts, 66, 38)) +>C : Symbol(C, Decl(restTuplesFromContextualTypes.ts, 66, 41)) +>f : Symbol(f, Decl(restTuplesFromContextualTypes.ts, 66, 45)) +>args : Symbol(args, Decl(restTuplesFromContextualTypes.ts, 66, 49)) +>A : Symbol(A, Decl(restTuplesFromContextualTypes.ts, 66, 22)) +>B : Symbol(B, Decl(restTuplesFromContextualTypes.ts, 66, 38)) +>g : Symbol(g, Decl(restTuplesFromContextualTypes.ts, 66, 66)) +>x : Symbol(x, Decl(restTuplesFromContextualTypes.ts, 66, 71)) +>B : Symbol(B, Decl(restTuplesFromContextualTypes.ts, 66, 38)) +>C : Symbol(C, Decl(restTuplesFromContextualTypes.ts, 66, 41)) +>args : Symbol(args, Decl(restTuplesFromContextualTypes.ts, 66, 85)) +>A : Symbol(A, Decl(restTuplesFromContextualTypes.ts, 66, 22)) +>C : Symbol(C, Decl(restTuplesFromContextualTypes.ts, 66, 41)) + +let g5 = pipe(() => true, b => 42); +>g5 : Symbol(g5, Decl(restTuplesFromContextualTypes.ts, 68, 3)) +>pipe : Symbol(pipe, Decl(restTuplesFromContextualTypes.ts, 64, 31)) +>b : Symbol(b, Decl(restTuplesFromContextualTypes.ts, 68, 25)) + +let g6 = pipe(x => "hello", s => s.length); +>g6 : Symbol(g6, Decl(restTuplesFromContextualTypes.ts, 69, 3)) +>pipe : Symbol(pipe, Decl(restTuplesFromContextualTypes.ts, 64, 31)) +>x : Symbol(x, Decl(restTuplesFromContextualTypes.ts, 69, 14)) +>s : Symbol(s, Decl(restTuplesFromContextualTypes.ts, 69, 27)) +>s.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) +>s : Symbol(s, Decl(restTuplesFromContextualTypes.ts, 69, 27)) +>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) + +let g7 = pipe((x, y) => 42, x => "" + x); +>g7 : Symbol(g7, Decl(restTuplesFromContextualTypes.ts, 70, 3)) +>pipe : Symbol(pipe, Decl(restTuplesFromContextualTypes.ts, 64, 31)) +>x : Symbol(x, Decl(restTuplesFromContextualTypes.ts, 70, 15)) +>y : Symbol(y, Decl(restTuplesFromContextualTypes.ts, 70, 17)) +>x : Symbol(x, Decl(restTuplesFromContextualTypes.ts, 70, 27)) +>x : Symbol(x, Decl(restTuplesFromContextualTypes.ts, 70, 27)) + +let g8 = pipe((x: number, y: string) => 42, x => "" + x); +>g8 : Symbol(g8, Decl(restTuplesFromContextualTypes.ts, 71, 3)) +>pipe : Symbol(pipe, Decl(restTuplesFromContextualTypes.ts, 64, 31)) +>x : Symbol(x, Decl(restTuplesFromContextualTypes.ts, 71, 15)) +>y : Symbol(y, Decl(restTuplesFromContextualTypes.ts, 71, 25)) +>x : Symbol(x, Decl(restTuplesFromContextualTypes.ts, 71, 43)) +>x : Symbol(x, Decl(restTuplesFromContextualTypes.ts, 71, 43)) + // Repro from #25288 declare var tuple: [number, string]; ->tuple : Symbol(tuple, Decl(restTuplesFromContextualTypes.ts, 60, 11)) +>tuple : Symbol(tuple, Decl(restTuplesFromContextualTypes.ts, 75, 11)) (function foo(a, b){}(...tuple)); ->foo : Symbol(foo, Decl(restTuplesFromContextualTypes.ts, 61, 1)) ->a : Symbol(a, Decl(restTuplesFromContextualTypes.ts, 61, 14)) ->b : Symbol(b, Decl(restTuplesFromContextualTypes.ts, 61, 16)) ->tuple : Symbol(tuple, Decl(restTuplesFromContextualTypes.ts, 60, 11)) +>foo : Symbol(foo, Decl(restTuplesFromContextualTypes.ts, 76, 1)) +>a : Symbol(a, Decl(restTuplesFromContextualTypes.ts, 76, 14)) +>b : Symbol(b, Decl(restTuplesFromContextualTypes.ts, 76, 16)) +>tuple : Symbol(tuple, Decl(restTuplesFromContextualTypes.ts, 75, 11)) // Repro from #25289 declare function take(cb: (a: number, b: string) => void): void; ->take : Symbol(take, Decl(restTuplesFromContextualTypes.ts, 61, 33)) ->cb : Symbol(cb, Decl(restTuplesFromContextualTypes.ts, 65, 22)) ->a : Symbol(a, Decl(restTuplesFromContextualTypes.ts, 65, 27)) ->b : Symbol(b, Decl(restTuplesFromContextualTypes.ts, 65, 37)) +>take : Symbol(take, Decl(restTuplesFromContextualTypes.ts, 76, 33)) +>cb : Symbol(cb, Decl(restTuplesFromContextualTypes.ts, 80, 22)) +>a : Symbol(a, Decl(restTuplesFromContextualTypes.ts, 80, 27)) +>b : Symbol(b, Decl(restTuplesFromContextualTypes.ts, 80, 37)) (function foo(...rest){}(1, '')); ->foo : Symbol(foo, Decl(restTuplesFromContextualTypes.ts, 67, 1)) ->rest : Symbol(rest, Decl(restTuplesFromContextualTypes.ts, 67, 14)) +>foo : Symbol(foo, Decl(restTuplesFromContextualTypes.ts, 82, 1)) +>rest : Symbol(rest, Decl(restTuplesFromContextualTypes.ts, 82, 14)) take(function(...rest){}); ->take : Symbol(take, Decl(restTuplesFromContextualTypes.ts, 61, 33)) ->rest : Symbol(rest, Decl(restTuplesFromContextualTypes.ts, 68, 14)) +>take : Symbol(take, Decl(restTuplesFromContextualTypes.ts, 76, 33)) +>rest : Symbol(rest, Decl(restTuplesFromContextualTypes.ts, 83, 14)) // Repro from #29833 type ArgsUnion = [number, string] | [number, Error]; ->ArgsUnion : Symbol(ArgsUnion, Decl(restTuplesFromContextualTypes.ts, 68, 26)) +>ArgsUnion : Symbol(ArgsUnion, Decl(restTuplesFromContextualTypes.ts, 83, 26)) >Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) type TupleUnionFunc = (...params: ArgsUnion) => number; ->TupleUnionFunc : Symbol(TupleUnionFunc, Decl(restTuplesFromContextualTypes.ts, 72, 52)) ->params : Symbol(params, Decl(restTuplesFromContextualTypes.ts, 73, 23)) ->ArgsUnion : Symbol(ArgsUnion, Decl(restTuplesFromContextualTypes.ts, 68, 26)) +>TupleUnionFunc : Symbol(TupleUnionFunc, Decl(restTuplesFromContextualTypes.ts, 87, 52)) +>params : Symbol(params, Decl(restTuplesFromContextualTypes.ts, 88, 23)) +>ArgsUnion : Symbol(ArgsUnion, Decl(restTuplesFromContextualTypes.ts, 83, 26)) const funcUnionTupleNoRest: TupleUnionFunc = (num, strOrErr) => { ->funcUnionTupleNoRest : Symbol(funcUnionTupleNoRest, Decl(restTuplesFromContextualTypes.ts, 75, 5)) ->TupleUnionFunc : Symbol(TupleUnionFunc, Decl(restTuplesFromContextualTypes.ts, 72, 52)) ->num : Symbol(num, Decl(restTuplesFromContextualTypes.ts, 75, 46)) ->strOrErr : Symbol(strOrErr, Decl(restTuplesFromContextualTypes.ts, 75, 50)) +>funcUnionTupleNoRest : Symbol(funcUnionTupleNoRest, Decl(restTuplesFromContextualTypes.ts, 90, 5)) +>TupleUnionFunc : Symbol(TupleUnionFunc, Decl(restTuplesFromContextualTypes.ts, 87, 52)) +>num : Symbol(num, Decl(restTuplesFromContextualTypes.ts, 90, 46)) +>strOrErr : Symbol(strOrErr, Decl(restTuplesFromContextualTypes.ts, 90, 50)) return num; ->num : Symbol(num, Decl(restTuplesFromContextualTypes.ts, 75, 46)) +>num : Symbol(num, Decl(restTuplesFromContextualTypes.ts, 90, 46)) }; const funcUnionTupleRest: TupleUnionFunc = (...params) => { ->funcUnionTupleRest : Symbol(funcUnionTupleRest, Decl(restTuplesFromContextualTypes.ts, 79, 5)) ->TupleUnionFunc : Symbol(TupleUnionFunc, Decl(restTuplesFromContextualTypes.ts, 72, 52)) ->params : Symbol(params, Decl(restTuplesFromContextualTypes.ts, 79, 44)) +>funcUnionTupleRest : Symbol(funcUnionTupleRest, Decl(restTuplesFromContextualTypes.ts, 94, 5)) +>TupleUnionFunc : Symbol(TupleUnionFunc, Decl(restTuplesFromContextualTypes.ts, 87, 52)) +>params : Symbol(params, Decl(restTuplesFromContextualTypes.ts, 94, 44)) const [num, strOrErr] = params; ->num : Symbol(num, Decl(restTuplesFromContextualTypes.ts, 80, 9)) ->strOrErr : Symbol(strOrErr, Decl(restTuplesFromContextualTypes.ts, 80, 13)) ->params : Symbol(params, Decl(restTuplesFromContextualTypes.ts, 79, 44)) +>num : Symbol(num, Decl(restTuplesFromContextualTypes.ts, 95, 9)) +>strOrErr : Symbol(strOrErr, Decl(restTuplesFromContextualTypes.ts, 95, 13)) +>params : Symbol(params, Decl(restTuplesFromContextualTypes.ts, 94, 44)) return num; ->num : Symbol(num, Decl(restTuplesFromContextualTypes.ts, 80, 9)) +>num : Symbol(num, Decl(restTuplesFromContextualTypes.ts, 95, 9)) }; diff --git a/tests/baselines/reference/restTuplesFromContextualTypes.types b/tests/baselines/reference/restTuplesFromContextualTypes.types index c282dbbae31..6dd2a6d90cb 100644 --- a/tests/baselines/reference/restTuplesFromContextualTypes.types +++ b/tests/baselines/reference/restTuplesFromContextualTypes.types @@ -351,6 +351,115 @@ function f4(t: T) { >x : T[number][] } +declare function f5(f: (...args: T) => U): (...args: T) => U; +>f5 : (f: (...args: T) => U) => (...args: T) => U +>f : (...args: T) => U +>args : T +>args : T + +let g0 = f5(() => "hello"); +>g0 : () => string +>f5(() => "hello") : () => string +>f5 : (f: (...args: T) => U) => (...args: T) => U +>() => "hello" : () => string +>"hello" : "hello" + +let g1 = f5((x, y) => 42); +>g1 : (x: any, y: any) => number +>f5((x, y) => 42) : (x: any, y: any) => number +>f5 : (f: (...args: T) => U) => (...args: T) => U +>(x, y) => 42 : (x: any, y: any) => number +>x : any +>y : any +>42 : 42 + +let g2 = f5((x: number, y) => 42); +>g2 : (x: number, y: any) => number +>f5((x: number, y) => 42) : (x: number, y: any) => number +>f5 : (f: (...args: T) => U) => (...args: T) => U +>(x: number, y) => 42 : (x: number, y: any) => number +>x : number +>y : any +>42 : 42 + +let g3 = f5((x: number, y: number) => x + y); +>g3 : (x: number, y: number) => number +>f5((x: number, y: number) => x + y) : (x: number, y: number) => number +>f5 : (f: (...args: T) => U) => (...args: T) => U +>(x: number, y: number) => x + y : (x: number, y: number) => number +>x : number +>y : number +>x + y : number +>x : number +>y : number + +let g4 = f5((...args) => true); +>g4 : (...args: any[]) => boolean +>f5((...args) => true) : (...args: any[]) => boolean +>f5 : (f: (...args: T) => U) => (...args: T) => U +>(...args) => true : (...args: any[]) => boolean +>args : any[] +>true : true + +declare function pipe(f: (...args: A) => B, g: (x: B) => C): (...args: A) => C; +>pipe : (f: (...args: A) => B, g: (x: B) => C) => (...args: A) => C +>f : (...args: A) => B +>args : A +>g : (x: B) => C +>x : B +>args : A + +let g5 = pipe(() => true, b => 42); +>g5 : () => number +>pipe(() => true, b => 42) : () => number +>pipe : (f: (...args: A) => B, g: (x: B) => C) => (...args: A) => C +>() => true : () => boolean +>true : true +>b => 42 : (b: boolean) => number +>b : boolean +>42 : 42 + +let g6 = pipe(x => "hello", s => s.length); +>g6 : (x: any) => number +>pipe(x => "hello", s => s.length) : (x: any) => number +>pipe : (f: (...args: A) => B, g: (x: B) => C) => (...args: A) => C +>x => "hello" : (x: any) => string +>x : any +>"hello" : "hello" +>s => s.length : (s: string) => number +>s : string +>s.length : number +>s : string +>length : number + +let g7 = pipe((x, y) => 42, x => "" + x); +>g7 : (x: any, y: any) => string +>pipe((x, y) => 42, x => "" + x) : (x: any, y: any) => string +>pipe : (f: (...args: A) => B, g: (x: B) => C) => (...args: A) => C +>(x, y) => 42 : (x: any, y: any) => number +>x : any +>y : any +>42 : 42 +>x => "" + x : (x: number) => string +>x : number +>"" + x : string +>"" : "" +>x : number + +let g8 = pipe((x: number, y: string) => 42, x => "" + x); +>g8 : (x: number, y: string) => string +>pipe((x: number, y: string) => 42, x => "" + x) : (x: number, y: string) => string +>pipe : (f: (...args: A) => B, g: (x: B) => C) => (...args: A) => C +>(x: number, y: string) => 42 : (x: number, y: string) => number +>x : number +>y : string +>42 : 42 +>x => "" + x : (x: number) => string +>x : number +>"" + x : string +>"" : "" +>x : number + // Repro from #25288 declare var tuple: [number, string]; From 4d7ec380a9a5d6f7e2f882d6bae9557d7414afb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E7=92=90?= Date: Tue, 26 Feb 2019 10:54:01 +0800 Subject: [PATCH 04/19] check completions with assignable rather than identity --- src/compiler/checker.ts | 2 +- .../completionsWithOptionalProperties.ts | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/completionsWithOptionalProperties.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index ddc958df0b4..c882227ba0c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7406,7 +7406,7 @@ namespace ts { const nameType = property.name && getLiteralTypeFromPropertyName(property.name); const name = nameType && isTypeUsableAsPropertyName(nameType) ? getPropertyNameFromType(nameType) : undefined; const expected = name === undefined ? undefined : getTypeOfPropertyOfType(contextualType, name); - return !!expected && isLiteralType(expected) && !isTypeIdenticalTo(getTypeOfNode(property), expected); + return !!expected && isLiteralType(expected) && !isTypeAssignableTo(getTypeOfNode(property), expected); }); } diff --git a/tests/cases/fourslash/completionsWithOptionalProperties.ts b/tests/cases/fourslash/completionsWithOptionalProperties.ts new file mode 100644 index 00000000000..e40029ddefa --- /dev/null +++ b/tests/cases/fourslash/completionsWithOptionalProperties.ts @@ -0,0 +1,18 @@ +/// +// @strict: true + +//// interface Options { +//// hello?: boolean; +//// world?: boolean; +//// } +//// declare function foo(options?: Options): void; +//// foo({ +//// hello: true, +//// /**/ +//// }); + +verify.completions({ + marker: "", + includes: ['world'] +}); + From ede6b9a5cbf2f2b3c44c706c0a78adfb2326cffc Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 26 Feb 2019 12:39:01 -0800 Subject: [PATCH 05/19] Issue errors for all circular type parameter constraints --- src/compiler/checker.ts | 19 +++++++++++++++---- src/compiler/diagnosticMessages.json | 4 ++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 958ceae0395..890f8f4beb8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7577,7 +7577,19 @@ namespace ts { constraintDepth++; let result = computeBaseConstraint(getSimplifiedType(t)); constraintDepth--; - if (!popTypeResolution() || nonTerminating) { + if (!popTypeResolution()) { + if (t.flags & TypeFlags.TypeParameter) { + const errorNode = getConstraintDeclaration(t); + if (errorNode) { + const diagnostic = error(errorNode, Diagnostics.Type_parameter_0_has_a_circular_constraint, typeToString(t)); + if (currentNode && !isNodeDescendantOf(errorNode, currentNode) && !isNodeDescendantOf(currentNode, errorNode)) { + addRelatedInfo(diagnostic, createDiagnosticForNode(currentNode, Diagnostics.Circularity_originates_in_type_at_this_location)); + } + } + } + result = circularConstraintType; + } + if (nonTerminating) { result = circularConstraintType; } t.immediateBaseConstraint = result || noConstraintType; @@ -23475,9 +23487,8 @@ namespace ts { checkSourceElement(node.constraint); checkSourceElement(node.default); const typeParameter = getDeclaredTypeOfTypeParameter(getSymbolOfNode(node)); - if (!hasNonCircularBaseConstraint(typeParameter)) { - error(getEffectiveConstraintOfTypeParameter(node), Diagnostics.Type_parameter_0_has_a_circular_constraint, typeToString(typeParameter)); - } + // Resolve base constraint to reveal circularity errors + getBaseConstraintOfType(typeParameter); if (!hasNonCircularTypeParameterDefault(typeParameter)) { error(node.default, Diagnostics.Type_parameter_0_has_a_circular_default, typeToString(typeParameter)); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 09b0f721292..5ae3a44b4b9 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2589,6 +2589,10 @@ "category": "Error", "code": 2750 }, + "Circularity originates in type at this location.": { + "category": "Error", + "code": 2751 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", From 5270b49bcc7d4e490c606dccd23fb96a3866e626 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 26 Feb 2019 12:39:14 -0800 Subject: [PATCH 06/19] Accept new baselines --- tests/baselines/reference/recursiveMappedTypes.errors.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/baselines/reference/recursiveMappedTypes.errors.txt b/tests/baselines/reference/recursiveMappedTypes.errors.txt index f2f59052a90..c003204cd78 100644 --- a/tests/baselines/reference/recursiveMappedTypes.errors.txt +++ b/tests/baselines/reference/recursiveMappedTypes.errors.txt @@ -32,6 +32,7 @@ tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(20,19): error TS258 [K in keyof Recurse1]: Recurse1[K] ~~~~~~~~~~~~~~ !!! error TS2313: Type parameter 'K' has a circular constraint. +!!! related TS2751 tests/cases/conformance/types/mapped/recursiveMappedTypes.ts:8:17: Circularity originates in type at this location. } // Repro from #27881 From 2212f4777a90830aa689574821153d41d06ae70c Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 26 Feb 2019 12:44:12 -0800 Subject: [PATCH 07/19] Add regression test --- .../types/mapped/recursiveMappedTypes.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/cases/conformance/types/mapped/recursiveMappedTypes.ts b/tests/cases/conformance/types/mapped/recursiveMappedTypes.ts index 69a0c1ca597..d5a5d63515f 100644 --- a/tests/cases/conformance/types/mapped/recursiveMappedTypes.ts +++ b/tests/cases/conformance/types/mapped/recursiveMappedTypes.ts @@ -61,3 +61,21 @@ type Remap2 = T extends object ? { [P in keyof T]: Remap2; } : T; type a = Remap1; // string[] type b = Remap2; // string[] + +// Repro from #29992 + +type NonOptionalKeys = { [P in keyof T]: undefined extends T[P] ? never : P }[keyof T]; +type Child = { [P in NonOptionalKeys]: T[P] } + +export interface ListWidget { + "type": "list", + "minimum_count": number, + "maximum_count": number, + "collapsable"?: boolean, //default to false, means all expanded + "each": Child; +} + +type ListChild = Child + +declare let x: ListChild; +x.type; From ecebc9ffeb02e4cd023c30a33e5cf70636124048 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 26 Feb 2019 12:44:18 -0800 Subject: [PATCH 08/19] Accept new baselines --- .../reference/recursiveMappedTypes.errors.txt | 24 ++++++++- .../reference/recursiveMappedTypes.js | 33 ++++++++++++ .../reference/recursiveMappedTypes.symbols | 54 +++++++++++++++++++ .../reference/recursiveMappedTypes.types | 36 +++++++++++++ 4 files changed, 146 insertions(+), 1 deletion(-) diff --git a/tests/baselines/reference/recursiveMappedTypes.errors.txt b/tests/baselines/reference/recursiveMappedTypes.errors.txt index c003204cd78..43a0e736d25 100644 --- a/tests/baselines/reference/recursiveMappedTypes.errors.txt +++ b/tests/baselines/reference/recursiveMappedTypes.errors.txt @@ -5,9 +5,10 @@ tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(8,11): error TS2313 tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(11,6): error TS2456: Type alias 'Recurse2' circularly references itself. tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(12,11): error TS2313: Type parameter 'K' has a circular constraint. tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(20,19): error TS2589: Type instantiation is excessively deep and possibly infinite. +tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(66,25): error TS2313: Type parameter 'P' has a circular constraint. -==== tests/cases/conformance/types/mapped/recursiveMappedTypes.ts (7 errors) ==== +==== tests/cases/conformance/types/mapped/recursiveMappedTypes.ts (8 errors) ==== // Recursive mapped types simply appear empty type Recurse = { @@ -84,4 +85,25 @@ tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(20,19): error TS258 type a = Remap1; // string[] type b = Remap2; // string[] + + // Repro from #29992 + + type NonOptionalKeys = { [P in keyof T]: undefined extends T[P] ? never : P }[keyof T]; + type Child = { [P in NonOptionalKeys]: T[P] } + ~~~~~~~~~~~~~~~~~~ +!!! error TS2313: Type parameter 'P' has a circular constraint. +!!! related TS2751 tests/cases/conformance/types/mapped/recursiveMappedTypes.ts:79:1: Circularity originates in type at this location. + + export interface ListWidget { + "type": "list", + "minimum_count": number, + "maximum_count": number, + "collapsable"?: boolean, //default to false, means all expanded + "each": Child; + } + + type ListChild = Child + + declare let x: ListChild; + x.type; \ No newline at end of file diff --git a/tests/baselines/reference/recursiveMappedTypes.js b/tests/baselines/reference/recursiveMappedTypes.js index e9e44a1df41..2cda37a8d45 100644 --- a/tests/baselines/reference/recursiveMappedTypes.js +++ b/tests/baselines/reference/recursiveMappedTypes.js @@ -60,6 +60,24 @@ type Remap2 = T extends object ? { [P in keyof T]: Remap2; } : T; type a = Remap1; // string[] type b = Remap2; // string[] + +// Repro from #29992 + +type NonOptionalKeys = { [P in keyof T]: undefined extends T[P] ? never : P }[keyof T]; +type Child = { [P in NonOptionalKeys]: T[P] } + +export interface ListWidget { + "type": "list", + "minimum_count": number, + "maximum_count": number, + "collapsable"?: boolean, //default to false, means all expanded + "each": Child; +} + +type ListChild = Child + +declare let x: ListChild; +x.type; //// [recursiveMappedTypes.js] @@ -70,9 +88,24 @@ function foo(arg) { return arg; } product.users; // (Transform | Transform)[] +x.type; //// [recursiveMappedTypes.d.ts] export declare type Circular = { [P in keyof T]: Circular; }; +declare type NonOptionalKeys = { + [P in keyof T]: undefined extends T[P] ? never : P; +}[keyof T]; +declare type Child = { + [P in NonOptionalKeys]: T[P]; +}; +export interface ListWidget { + "type": "list"; + "minimum_count": number; + "maximum_count": number; + "collapsable"?: boolean; + "each": Child; +} +export {}; diff --git a/tests/baselines/reference/recursiveMappedTypes.symbols b/tests/baselines/reference/recursiveMappedTypes.symbols index 1638dc03f56..777a6a722fa 100644 --- a/tests/baselines/reference/recursiveMappedTypes.symbols +++ b/tests/baselines/reference/recursiveMappedTypes.symbols @@ -165,3 +165,57 @@ type b = Remap2; // string[] >b : Symbol(b, Decl(recursiveMappedTypes.ts, 59, 26)) >Remap2 : Symbol(Remap2, Decl(recursiveMappedTypes.ts, 56, 51)) +// Repro from #29992 + +type NonOptionalKeys = { [P in keyof T]: undefined extends T[P] ? never : P }[keyof T]; +>NonOptionalKeys : Symbol(NonOptionalKeys, Decl(recursiveMappedTypes.ts, 60, 26)) +>T : Symbol(T, Decl(recursiveMappedTypes.ts, 64, 21)) +>P : Symbol(P, Decl(recursiveMappedTypes.ts, 64, 29)) +>T : Symbol(T, Decl(recursiveMappedTypes.ts, 64, 21)) +>T : Symbol(T, Decl(recursiveMappedTypes.ts, 64, 21)) +>P : Symbol(P, Decl(recursiveMappedTypes.ts, 64, 29)) +>P : Symbol(P, Decl(recursiveMappedTypes.ts, 64, 29)) +>T : Symbol(T, Decl(recursiveMappedTypes.ts, 64, 21)) + +type Child = { [P in NonOptionalKeys]: T[P] } +>Child : Symbol(Child, Decl(recursiveMappedTypes.ts, 64, 90)) +>T : Symbol(T, Decl(recursiveMappedTypes.ts, 65, 11)) +>P : Symbol(P, Decl(recursiveMappedTypes.ts, 65, 19)) +>NonOptionalKeys : Symbol(NonOptionalKeys, Decl(recursiveMappedTypes.ts, 60, 26)) +>T : Symbol(T, Decl(recursiveMappedTypes.ts, 65, 11)) +>T : Symbol(T, Decl(recursiveMappedTypes.ts, 65, 11)) +>P : Symbol(P, Decl(recursiveMappedTypes.ts, 65, 19)) + +export interface ListWidget { +>ListWidget : Symbol(ListWidget, Decl(recursiveMappedTypes.ts, 65, 51)) + + "type": "list", +>"type" : Symbol(ListWidget["type"], Decl(recursiveMappedTypes.ts, 67, 29)) + + "minimum_count": number, +>"minimum_count" : Symbol(ListWidget["minimum_count"], Decl(recursiveMappedTypes.ts, 68, 19)) + + "maximum_count": number, +>"maximum_count" : Symbol(ListWidget["maximum_count"], Decl(recursiveMappedTypes.ts, 69, 28)) + + "collapsable"?: boolean, //default to false, means all expanded +>"collapsable" : Symbol(ListWidget["collapsable"], Decl(recursiveMappedTypes.ts, 70, 28)) + + "each": Child; +>"each" : Symbol(ListWidget["each"], Decl(recursiveMappedTypes.ts, 71, 28)) +>Child : Symbol(Child, Decl(recursiveMappedTypes.ts, 64, 90)) +>ListWidget : Symbol(ListWidget, Decl(recursiveMappedTypes.ts, 65, 51)) +} + +type ListChild = Child +>ListChild : Symbol(ListChild, Decl(recursiveMappedTypes.ts, 73, 1)) +>Child : Symbol(Child, Decl(recursiveMappedTypes.ts, 64, 90)) +>ListWidget : Symbol(ListWidget, Decl(recursiveMappedTypes.ts, 65, 51)) + +declare let x: ListChild; +>x : Symbol(x, Decl(recursiveMappedTypes.ts, 77, 11)) +>ListChild : Symbol(ListChild, Decl(recursiveMappedTypes.ts, 73, 1)) + +x.type; +>x : Symbol(x, Decl(recursiveMappedTypes.ts, 77, 11)) + diff --git a/tests/baselines/reference/recursiveMappedTypes.types b/tests/baselines/reference/recursiveMappedTypes.types index 126d1e1d740..34cfd2d6100 100644 --- a/tests/baselines/reference/recursiveMappedTypes.types +++ b/tests/baselines/reference/recursiveMappedTypes.types @@ -97,3 +97,39 @@ type a = Remap1; // string[] type b = Remap2; // string[] >b : string[] +// Repro from #29992 + +type NonOptionalKeys = { [P in keyof T]: undefined extends T[P] ? never : P }[keyof T]; +>NonOptionalKeys : { [P in keyof T]: undefined extends T[P] ? never : P; }[keyof T] + +type Child = { [P in NonOptionalKeys]: T[P] } +>Child : Child + +export interface ListWidget { + "type": "list", +>"type" : "list" + + "minimum_count": number, +>"minimum_count" : number + + "maximum_count": number, +>"maximum_count" : number + + "collapsable"?: boolean, //default to false, means all expanded +>"collapsable" : boolean + + "each": Child; +>"each" : Child +} + +type ListChild = Child +>ListChild : Child + +declare let x: ListChild; +>x : Child + +x.type; +>x.type : any +>x : Child +>type : any + From 3e4b9c07d28c5a5347d297fe4da669a0b0fa4d5c Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 26 Feb 2019 14:01:03 -0800 Subject: [PATCH 09/19] Revert "Do not wrap npm path with quotes" This reverts commit 1ed5e1c63b71e0a4e7fd0493a37e43a7ef518ebb. --- src/typingsInstaller/nodeTypingsInstaller.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/typingsInstaller/nodeTypingsInstaller.ts b/src/typingsInstaller/nodeTypingsInstaller.ts index 2facb1223d0..1d75218c883 100644 --- a/src/typingsInstaller/nodeTypingsInstaller.ts +++ b/src/typingsInstaller/nodeTypingsInstaller.ts @@ -89,6 +89,10 @@ namespace ts.server.typingsInstaller { log); this.npmPath = npmLocation !== undefined ? npmLocation : getDefaultNPMLocation(process.argv[0]); + // If the NPM path contains spaces and isn't wrapped in quotes, do so. + if (stringContains(this.npmPath, " ") && this.npmPath[0] !== `"`) { + this.npmPath = `"${this.npmPath}"`; + } if (this.log.isEnabled()) { this.log.writeLine(`Process id: ${process.pid}`); this.log.writeLine(`NPM location: ${this.npmPath} (explicit '${Arguments.NpmLocation}' ${npmLocation === undefined ? "not " : ""} provided)`); From fd10c12116b7caf5fe8766812c3c26fac4f43c9c Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Tue, 26 Feb 2019 14:01:42 -0800 Subject: [PATCH 10/19] Revert "Use execFileSync in typing installer" This reverts commit bc386c11fd3f026ca84ec556b1b8fb4a2eee0038. --- .../unittests/tsserver/typingsInstaller.ts | 12 ++++++------ src/typingsInstaller/nodeTypingsInstaller.ts | 16 ++++++++-------- src/typingsInstallerCore/typingsInstaller.ts | 17 +++++------------ 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/testRunner/unittests/tsserver/typingsInstaller.ts b/src/testRunner/unittests/tsserver/typingsInstaller.ts index 5d648ba23a2..76df9934682 100644 --- a/src/testRunner/unittests/tsserver/typingsInstaller.ts +++ b/src/testRunner/unittests/tsserver/typingsInstaller.ts @@ -1684,9 +1684,9 @@ namespace ts.projectSystem { TI.getNpmCommandForInstallation(npmPath, tsVersion, packageNames, packageNames.length - Math.ceil(packageNames.length / 2)).command ]; it("works when the command is too long to install all packages at once", () => { - const commands: [string, string[]][] = []; - const hasError = TI.installNpmPackages(npmPath, tsVersion, packageNames, (file, args) => { - commands.push([file, args]); + const commands: string[] = []; + const hasError = TI.installNpmPackages(npmPath, tsVersion, packageNames, command => { + commands.push(command); return false; }); assert.isFalse(hasError); @@ -1694,9 +1694,9 @@ namespace ts.projectSystem { }); it("installs remaining packages when one of the partial command fails", () => { - const commands: [string, string[]][] = []; - const hasError = TI.installNpmPackages(npmPath, tsVersion, packageNames, (file, args) => { - commands.push([file, args]); + const commands: string[] = []; + const hasError = TI.installNpmPackages(npmPath, tsVersion, packageNames, command => { + commands.push(command); return commands.length === 1; }); assert.isTrue(hasError); diff --git a/src/typingsInstaller/nodeTypingsInstaller.ts b/src/typingsInstaller/nodeTypingsInstaller.ts index 1d75218c883..62bdcfce260 100644 --- a/src/typingsInstaller/nodeTypingsInstaller.ts +++ b/src/typingsInstaller/nodeTypingsInstaller.ts @@ -70,10 +70,10 @@ namespace ts.server.typingsInstaller { cwd: string; encoding: "utf-8"; } - type ExecFileSync = (file: string, args: string[], options: ExecSyncOptions) => string; + type ExecSync = (command: string, options: ExecSyncOptions) => string; export class NodeTypingsInstaller extends TypingsInstaller { - private readonly nodeExecFileSync: ExecFileSync; + private readonly nodeExecSync: ExecSync; private readonly npmPath: string; readonly typesRegistry: Map>; @@ -97,7 +97,7 @@ namespace ts.server.typingsInstaller { this.log.writeLine(`Process id: ${process.pid}`); this.log.writeLine(`NPM location: ${this.npmPath} (explicit '${Arguments.NpmLocation}' ${npmLocation === undefined ? "not " : ""} provided)`); } - ({ execFileSync: this.nodeExecFileSync } = require("child_process")); + ({ execSync: this.nodeExecSync } = require("child_process")); this.ensurePackageDirectoryExists(globalTypingsCacheLocation); @@ -105,7 +105,7 @@ namespace ts.server.typingsInstaller { if (this.log.isEnabled()) { this.log.writeLine(`Updating ${typesRegistryPackageName} npm package...`); } - this.execFileSyncAndLog(this.npmPath, ["install", "--ignore-scripts", `${typesRegistryPackageName}@${this.latestDistTag}`], { cwd: globalTypingsCacheLocation }); + this.execSyncAndLog(`${this.npmPath} install --ignore-scripts ${typesRegistryPackageName}@${this.latestDistTag}`, { cwd: globalTypingsCacheLocation }); if (this.log.isEnabled()) { this.log.writeLine(`Updated ${typesRegistryPackageName} npm package`); } @@ -189,7 +189,7 @@ namespace ts.server.typingsInstaller { this.log.writeLine(`#${requestId} with arguments'${JSON.stringify(packageNames)}'.`); } const start = Date.now(); - const hasError = installNpmPackages(this.npmPath, version, packageNames, (file, args) => this.execFileSyncAndLog(file, args, { cwd })); + const hasError = installNpmPackages(this.npmPath, version, packageNames, command => this.execSyncAndLog(command, { cwd })); if (this.log.isEnabled()) { this.log.writeLine(`npm install #${requestId} took: ${Date.now() - start} ms`); } @@ -197,12 +197,12 @@ namespace ts.server.typingsInstaller { } /** Returns 'true' in case of error. */ - private execFileSyncAndLog(file: string, args: string[], options: Pick): boolean { + private execSyncAndLog(command: string, options: Pick): boolean { if (this.log.isEnabled()) { - this.log.writeLine(`Exec: ${file} ${args.join(" ")}`); + this.log.writeLine(`Exec: ${command}`); } try { - const stdout = this.nodeExecFileSync(file, args, { ...options, encoding: "utf-8" }); + const stdout = this.nodeExecSync(command, { ...options, encoding: "utf-8" }); if (this.log.isEnabled()) { this.log.writeLine(` Succeeded. stdout:${indent(sys.newLine, stdout)}`); } diff --git a/src/typingsInstallerCore/typingsInstaller.ts b/src/typingsInstallerCore/typingsInstaller.ts index 3d0858d7dfe..df83f1a677c 100644 --- a/src/typingsInstallerCore/typingsInstaller.ts +++ b/src/typingsInstallerCore/typingsInstaller.ts @@ -31,35 +31,28 @@ namespace ts.server.typingsInstaller { } /*@internal*/ - export function installNpmPackages(npmPath: string, tsVersion: string, packageNames: string[], install: (file: string, args: string[]) => boolean) { + export function installNpmPackages(npmPath: string, tsVersion: string, packageNames: string[], install: (command: string) => boolean) { let hasError = false; for (let remaining = packageNames.length; remaining > 0;) { const result = getNpmCommandForInstallation(npmPath, tsVersion, packageNames, remaining); remaining = result.remaining; - hasError = install(result.command[0], result.command[1]) || hasError; + hasError = install(result.command) || hasError; } return hasError; } - function getUserAgent(tsVersion: string) { - return `--user-agent="typesInstaller/${tsVersion}"`; - } - const npmInstall = "install", ignoreScripts = "--ignore-scripts", saveDev = "--save-dev"; - const commandBaseLength = npmInstall.length + ignoreScripts.length + saveDev.length + getUserAgent("").length + 5; /*@internal*/ export function getNpmCommandForInstallation(npmPath: string, tsVersion: string, packageNames: string[], remaining: number) { const sliceStart = packageNames.length - remaining; - let packages: string[], toSlice = remaining; + let command: string, toSlice = remaining; while (true) { - packages = toSlice === packageNames.length ? packageNames : packageNames.slice(sliceStart, sliceStart + toSlice); - const commandLength = npmPath.length + commandBaseLength + packages.join(" ").length + tsVersion.length; - if (commandLength < 8000) { + command = `${npmPath} install --ignore-scripts ${(toSlice === packageNames.length ? packageNames : packageNames.slice(sliceStart, sliceStart + toSlice)).join(" ")} --save-dev --user-agent="typesInstaller/${tsVersion}"`; + if (command.length < 8000) { break; } toSlice = toSlice - Math.floor(toSlice / 2); } - const command: [string, string[]] = [npmPath, [npmInstall, ignoreScripts, ...packages, saveDev, getUserAgent(tsVersion)]]; return { command, remaining: remaining - toSlice }; } From aedffe049d74ba1893d92dbec41b0f389609c364 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 27 Feb 2019 11:50:04 -0800 Subject: [PATCH 11/19] Revert "Merge pull request #27697 from mattmccutchen/issue-27118" This reverts commit 2dfb6202ed03e04ba1dcc330eea219c50fe48c66, reversing changes made to bbf559b9c7fd21b984d7cb538140c74e3d6a6b45. --- src/compiler/checker.ts | 9 +- .../reference/conditionalTypes2.errors.txt | 122 ++- .../baselines/reference/conditionalTypes2.js | 121 ++- .../reference/conditionalTypes2.symbols | 870 +++++++++--------- .../reference/conditionalTypes2.types | 115 ++- .../types/conditional/conditionalTypes2.ts | 57 +- 6 files changed, 687 insertions(+), 607 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7e6cb97a930..80853ca2eaf 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12724,11 +12724,10 @@ namespace ts { else if (source.flags & TypeFlags.Conditional) { if (target.flags & TypeFlags.Conditional) { // Two conditional types 'T1 extends U1 ? X1 : Y1' and 'T2 extends U2 ? X2 : Y2' are related if - // they have the same distributivity, T1 and T2 are identical types, U1 and U2 are identical - // types, X1 is related to X2, and Y1 is related to Y2. - if ((source).root.isDistributive === (target).root.isDistributive && - isTypeIdenticalTo((source).extendsType, (target).extendsType) && - isTypeIdenticalTo((source).checkType, (target).checkType)) { + // one of T1 and T2 is related to the other, U1 and U2 are identical types, X1 is related to X2, + // and Y1 is related to Y2. + if (isTypeIdenticalTo((source).extendsType, (target).extendsType) && + (isRelatedTo((source).checkType, (target).checkType) || isRelatedTo((target).checkType, (source).checkType))) { if (result = isRelatedTo(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target), reportErrors)) { result &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), reportErrors); } diff --git a/tests/baselines/reference/conditionalTypes2.errors.txt b/tests/baselines/reference/conditionalTypes2.errors.txt index 343a0a8412c..a1a23b6da18 100644 --- a/tests/baselines/reference/conditionalTypes2.errors.txt +++ b/tests/baselines/reference/conditionalTypes2.errors.txt @@ -1,38 +1,29 @@ -tests/cases/conformance/types/conditional/conditionalTypes2.ts(16,5): error TS2322: Type 'Covariant' is not assignable to type 'Covariant'. - Types of property 'foo' are incompatible. - Type 'B extends string ? B : number' is not assignable to type 'A extends string ? A : number'. -tests/cases/conformance/types/conditional/conditionalTypes2.ts(17,5): error TS2322: Type 'Covariant' is not assignable to type 'Covariant'. - Types of property 'foo' are incompatible. - Type 'A extends string ? A : number' is not assignable to type 'B extends string ? B : number'. -tests/cases/conformance/types/conditional/conditionalTypes2.ts(21,5): error TS2322: Type 'Contravariant' is not assignable to type 'Contravariant'. - Types of property 'foo' are incompatible. - Type 'B extends string ? keyof B : number' is not assignable to type 'A extends string ? keyof A : number'. -tests/cases/conformance/types/conditional/conditionalTypes2.ts(22,5): error TS2322: Type 'Contravariant' is not assignable to type 'Contravariant'. - Types of property 'foo' are incompatible. - Type 'A extends string ? keyof A : number' is not assignable to type 'B extends string ? keyof B : number'. -tests/cases/conformance/types/conditional/conditionalTypes2.ts(26,5): error TS2322: Type 'Invariant' is not assignable to type 'Invariant'. +tests/cases/conformance/types/conditional/conditionalTypes2.ts(15,5): error TS2322: Type 'Covariant' is not assignable to type 'Covariant'. + Type 'A' is not assignable to type 'B'. +tests/cases/conformance/types/conditional/conditionalTypes2.ts(19,5): error TS2322: Type 'Contravariant' is not assignable to type 'Contravariant'. + Type 'A' is not assignable to type 'B'. +tests/cases/conformance/types/conditional/conditionalTypes2.ts(24,5): error TS2322: Type 'Invariant' is not assignable to type 'Invariant'. Types of property 'foo' are incompatible. Type 'B extends string ? keyof B : B' is not assignable to type 'A extends string ? keyof A : A'. -tests/cases/conformance/types/conditional/conditionalTypes2.ts(27,5): error TS2322: Type 'Invariant' is not assignable to type 'Invariant'. + Type 'keyof B' is not assignable to type 'keyof A'. + Type 'string | number | symbol' is not assignable to type 'keyof A'. + Type 'string' is not assignable to type 'keyof A'. +tests/cases/conformance/types/conditional/conditionalTypes2.ts(25,5): error TS2322: Type 'Invariant' is not assignable to type 'Invariant'. Types of property 'foo' are incompatible. Type 'A extends string ? keyof A : A' is not assignable to type 'B extends string ? keyof B : B'. -tests/cases/conformance/types/conditional/conditionalTypes2.ts(75,12): error TS2345: Argument of type 'Extract, Bar>' is not assignable to parameter of type '{ foo: string; bat: string; }'. + Type 'A' is not assignable to type 'B'. +tests/cases/conformance/types/conditional/conditionalTypes2.ts(73,12): error TS2345: Argument of type 'Extract, Bar>' is not assignable to parameter of type '{ foo: string; bat: string; }'. Property 'bat' is missing in type 'Bar & Foo' but required in type '{ foo: string; bat: string; }'. Type 'Extract' is not assignable to type '{ foo: string; bat: string; }'. Property 'bat' is missing in type 'Bar & Foo' but required in type '{ foo: string; bat: string; }'. -tests/cases/conformance/types/conditional/conditionalTypes2.ts(76,12): error TS2345: Argument of type 'Extract' is not assignable to parameter of type '{ foo: string; bat: string; }'. +tests/cases/conformance/types/conditional/conditionalTypes2.ts(74,12): error TS2345: Argument of type 'Extract' is not assignable to parameter of type '{ foo: string; bat: string; }'. Property 'bat' is missing in type 'Foo & Bar' but required in type '{ foo: string; bat: string; }'. -tests/cases/conformance/types/conditional/conditionalTypes2.ts(77,12): error TS2345: Argument of type 'Extract2' is not assignable to parameter of type '{ foo: string; bat: string; }'. +tests/cases/conformance/types/conditional/conditionalTypes2.ts(75,12): error TS2345: Argument of type 'Extract2' is not assignable to parameter of type '{ foo: string; bat: string; }'. Type 'T extends Bar ? T : never' is not assignable to type '{ foo: string; bat: string; }'. Type 'Bar & Foo & T' is not assignable to type '{ foo: string; bat: string; }'. -tests/cases/conformance/types/conditional/conditionalTypes2.ts(165,5): error TS2322: Type 'MyElement' is not assignable to type 'MyElement'. -tests/cases/conformance/types/conditional/conditionalTypes2.ts(170,5): error TS2322: Type 'MyAcceptor' is not assignable to type 'MyAcceptor'. -tests/cases/conformance/types/conditional/conditionalTypes2.ts(177,5): error TS2322: Type 'Dist' is not assignable to type 'Aux<{ a: T; }>'. -==== tests/cases/conformance/types/conditional/conditionalTypes2.ts (12 errors) ==== - // #27118: Conditional types are now invariant in the check type. - +==== tests/cases/conformance/types/conditional/conditionalTypes2.ts (7 errors) ==== interface Covariant { foo: T extends string ? T : number; } @@ -46,29 +37,19 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(177,5): error TS2 } function f1(a: Covariant, b: Covariant) { - a = b; // Error - ~ -!!! error TS2322: Type 'Covariant' is not assignable to type 'Covariant'. -!!! error TS2322: Types of property 'foo' are incompatible. -!!! error TS2322: Type 'B extends string ? B : number' is not assignable to type 'A extends string ? A : number'. + a = b; b = a; // Error ~ !!! error TS2322: Type 'Covariant' is not assignable to type 'Covariant'. -!!! error TS2322: Types of property 'foo' are incompatible. -!!! error TS2322: Type 'A extends string ? A : number' is not assignable to type 'B extends string ? B : number'. +!!! error TS2322: Type 'A' is not assignable to type 'B'. } function f2(a: Contravariant, b: Contravariant) { a = b; // Error ~ !!! error TS2322: Type 'Contravariant' is not assignable to type 'Contravariant'. -!!! error TS2322: Types of property 'foo' are incompatible. -!!! error TS2322: Type 'B extends string ? keyof B : number' is not assignable to type 'A extends string ? keyof A : number'. - b = a; // Error - ~ -!!! error TS2322: Type 'Contravariant' is not assignable to type 'Contravariant'. -!!! error TS2322: Types of property 'foo' are incompatible. -!!! error TS2322: Type 'A extends string ? keyof A : number' is not assignable to type 'B extends string ? keyof B : number'. +!!! error TS2322: Type 'A' is not assignable to type 'B'. + b = a; } function f3(a: Invariant, b: Invariant) { @@ -77,11 +58,15 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(177,5): error TS2 !!! error TS2322: Type 'Invariant' is not assignable to type 'Invariant'. !!! error TS2322: Types of property 'foo' are incompatible. !!! error TS2322: Type 'B extends string ? keyof B : B' is not assignable to type 'A extends string ? keyof A : A'. +!!! error TS2322: Type 'keyof B' is not assignable to type 'keyof A'. +!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'keyof A'. +!!! error TS2322: Type 'string' is not assignable to type 'keyof A'. b = a; // Error ~ !!! error TS2322: Type 'Invariant' is not assignable to type 'Invariant'. !!! error TS2322: Types of property 'foo' are incompatible. !!! error TS2322: Type 'A extends string ? keyof A : A' is not assignable to type 'B extends string ? keyof B : B'. +!!! error TS2322: Type 'A' is not assignable to type 'B'. } // Extract is a T that is known to be a Function @@ -135,13 +120,13 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(177,5): error TS2 !!! error TS2345: Property 'bat' is missing in type 'Bar & Foo' but required in type '{ foo: string; bat: string; }'. !!! error TS2345: Type 'Extract' is not assignable to type '{ foo: string; bat: string; }'. !!! error TS2345: Property 'bat' is missing in type 'Bar & Foo' but required in type '{ foo: string; bat: string; }'. -!!! related TS2728 tests/cases/conformance/types/conditional/conditionalTypes2.ts:64:43: 'bat' is declared here. -!!! related TS2728 tests/cases/conformance/types/conditional/conditionalTypes2.ts:64:43: 'bat' is declared here. +!!! related TS2728 tests/cases/conformance/types/conditional/conditionalTypes2.ts:62:43: 'bat' is declared here. +!!! related TS2728 tests/cases/conformance/types/conditional/conditionalTypes2.ts:62:43: 'bat' is declared here. fooBat(y); // Error ~ !!! error TS2345: Argument of type 'Extract' is not assignable to parameter of type '{ foo: string; bat: string; }'. !!! error TS2345: Property 'bat' is missing in type 'Foo & Bar' but required in type '{ foo: string; bat: string; }'. -!!! related TS2728 tests/cases/conformance/types/conditional/conditionalTypes2.ts:64:43: 'bat' is declared here. +!!! related TS2728 tests/cases/conformance/types/conditional/conditionalTypes2.ts:62:43: 'bat' is declared here. fooBat(z); // Error ~ !!! error TS2345: Argument of type 'Extract2' is not assignable to parameter of type '{ foo: string; bat: string; }'. @@ -149,6 +134,38 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(177,5): error TS2 !!! error TS2345: Type 'Bar & Foo & T' is not assignable to type '{ foo: string; bat: string; }'. } + // Repros from #22860 + + class Opt { + toVector(): Vector { + return undefined; + } + } + + interface Seq { + tail(): Opt>; + } + + class Vector implements Seq { + tail(): Opt> { + return undefined; + } + partition2(predicate:(v:T)=>v is U): [Vector,Vector>]; + partition2(predicate:(x:T)=>boolean): [Vector,Vector]; + partition2(predicate:(v:T)=>boolean): [Vector,Vector] { + return undefined; + } + } + + interface A1 { + bat: B1>; + } + + interface B1 extends A1 { + bat: B1>; + boom: T extends any ? true : true + } + // Repro from #22899 declare function toString1(value: object | Function): string ; @@ -229,29 +246,4 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(177,5): error TS2 }; type PCCA = ProductComplementComplement['a']; type PCCB = ProductComplementComplement['b']; - - // Repros from #27118 - - type MyElement = [A] extends [[infer E]] ? E : never; - function oops(arg: MyElement): MyElement { - return arg; // Unsound, should be error - ~~~~~~~~~~~ -!!! error TS2322: Type 'MyElement' is not assignable to type 'MyElement'. - } - - type MyAcceptor = [A] extends [[infer E]] ? (arg: E) => void : never; - function oops2(arg: MyAcceptor): MyAcceptor { - return arg; // Unsound, should be error - ~~~~~~~~~~~ -!!! error TS2322: Type 'MyAcceptor' is not assignable to type 'MyAcceptor'. - } - - type Dist = T extends number ? number : string; - type Aux = A["a"] extends number ? number : string; - type Nondist = Aux<{a: T}>; - function oops3(arg: Dist): Nondist { - return arg; // Unsound, should be error - ~~~~~~~~~~~ -!!! error TS2322: Type 'Dist' is not assignable to type 'Aux<{ a: T; }>'. - } \ No newline at end of file diff --git a/tests/baselines/reference/conditionalTypes2.js b/tests/baselines/reference/conditionalTypes2.js index c59c996711d..4f4f35e821a 100644 --- a/tests/baselines/reference/conditionalTypes2.js +++ b/tests/baselines/reference/conditionalTypes2.js @@ -1,6 +1,4 @@ //// [conditionalTypes2.ts] -// #27118: Conditional types are now invariant in the check type. - interface Covariant { foo: T extends string ? T : number; } @@ -14,13 +12,13 @@ interface Invariant { } function f1(a: Covariant, b: Covariant) { - a = b; // Error + a = b; b = a; // Error } function f2(a: Contravariant, b: Contravariant) { a = b; // Error - b = a; // Error + b = a; } function f3(a: Invariant, b: Invariant) { @@ -78,6 +76,38 @@ function f21(x: Extract, Bar>, y: Extract, z: E fooBat(z); // Error } +// Repros from #22860 + +class Opt { + toVector(): Vector { + return undefined; + } +} + +interface Seq { + tail(): Opt>; +} + +class Vector implements Seq { + tail(): Opt> { + return undefined; + } + partition2(predicate:(v:T)=>v is U): [Vector,Vector>]; + partition2(predicate:(x:T)=>boolean): [Vector,Vector]; + partition2(predicate:(v:T)=>boolean): [Vector,Vector] { + return undefined; + } +} + +interface A1 { + bat: B1>; +} + +interface B1 extends A1 { + bat: B1>; + boom: T extends any ? true : true +} + // Repro from #22899 declare function toString1(value: object | Function): string ; @@ -158,37 +188,17 @@ type ProductComplementComplement = { }; type PCCA = ProductComplementComplement['a']; type PCCB = ProductComplementComplement['b']; - -// Repros from #27118 - -type MyElement = [A] extends [[infer E]] ? E : never; -function oops(arg: MyElement): MyElement { - return arg; // Unsound, should be error -} - -type MyAcceptor = [A] extends [[infer E]] ? (arg: E) => void : never; -function oops2(arg: MyAcceptor): MyAcceptor { - return arg; // Unsound, should be error -} - -type Dist = T extends number ? number : string; -type Aux = A["a"] extends number ? number : string; -type Nondist = Aux<{a: T}>; -function oops3(arg: Dist): Nondist { - return arg; // Unsound, should be error -} //// [conditionalTypes2.js] "use strict"; -// #27118: Conditional types are now invariant in the check type. function f1(a, b) { - a = b; // Error + a = b; b = a; // Error } function f2(a, b) { a = b; // Error - b = a; // Error + b = a; } function f3(a, b) { a = b; // Error @@ -229,21 +239,32 @@ function f21(x, y, z) { fooBat(y); // Error fooBat(z); // Error } +// Repros from #22860 +var Opt = /** @class */ (function () { + function Opt() { + } + Opt.prototype.toVector = function () { + return undefined; + }; + return Opt; +}()); +var Vector = /** @class */ (function () { + function Vector() { + } + Vector.prototype.tail = function () { + return undefined; + }; + Vector.prototype.partition2 = function (predicate) { + return undefined; + }; + return Vector; +}()); function foo(value) { if (isFunction(value)) { toString1(value); toString2(value); } } -function oops(arg) { - return arg; // Unsound, should be error -} -function oops2(arg) { - return arg; // Unsound, should be error -} -function oops3(arg) { - return arg; // Unsound, should be error -} //// [conditionalTypes2.d.ts] @@ -281,6 +302,24 @@ declare function fooBat(x: { declare type Extract2 = T extends U ? T extends V ? T : never : never; declare function f20(x: Extract, Bar>, y: Extract, z: Extract2): void; declare function f21(x: Extract, Bar>, y: Extract, z: Extract2): void; +declare class Opt { + toVector(): Vector; +} +interface Seq { + tail(): Opt>; +} +declare class Vector implements Seq { + tail(): Opt>; + partition2(predicate: (v: T) => v is U): [Vector, Vector>]; + partition2(predicate: (x: T) => boolean): [Vector, Vector]; +} +interface A1 { + bat: B1>; +} +interface B1 extends A1 { + bat: B1>; + boom: T extends any ? true : true; +} declare function toString1(value: object | Function): string; declare function toString2(value: Function): string; declare function foo(value: T): void; @@ -353,15 +392,3 @@ declare type ProductComplementComplement = { }; declare type PCCA = ProductComplementComplement['a']; declare type PCCB = ProductComplementComplement['b']; -declare type MyElement = [A] extends [[infer E]] ? E : never; -declare function oops(arg: MyElement): MyElement; -declare type MyAcceptor = [A] extends [[infer E]] ? (arg: E) => void : never; -declare function oops2(arg: MyAcceptor): MyAcceptor; -declare type Dist = T extends number ? number : string; -declare type Aux = A["a"] extends number ? number : string; -declare type Nondist = Aux<{ - a: T; -}>; -declare function oops3(arg: Dist): Nondist; diff --git a/tests/baselines/reference/conditionalTypes2.symbols b/tests/baselines/reference/conditionalTypes2.symbols index 7bbf837eece..b164d26e450 100644 --- a/tests/baselines/reference/conditionalTypes2.symbols +++ b/tests/baselines/reference/conditionalTypes2.symbols @@ -1,655 +1,687 @@ === tests/cases/conformance/types/conditional/conditionalTypes2.ts === -// #27118: Conditional types are now invariant in the check type. - interface Covariant { >Covariant : Symbol(Covariant, Decl(conditionalTypes2.ts, 0, 0)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 2, 20)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 0, 20)) foo: T extends string ? T : number; ->foo : Symbol(Covariant.foo, Decl(conditionalTypes2.ts, 2, 24)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 2, 20)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 2, 20)) +>foo : Symbol(Covariant.foo, Decl(conditionalTypes2.ts, 0, 24)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 0, 20)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 0, 20)) } interface Contravariant { ->Contravariant : Symbol(Contravariant, Decl(conditionalTypes2.ts, 4, 1)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 6, 24)) +>Contravariant : Symbol(Contravariant, Decl(conditionalTypes2.ts, 2, 1)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 4, 24)) foo: T extends string ? keyof T : number; ->foo : Symbol(Contravariant.foo, Decl(conditionalTypes2.ts, 6, 28)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 6, 24)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 6, 24)) +>foo : Symbol(Contravariant.foo, Decl(conditionalTypes2.ts, 4, 28)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 4, 24)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 4, 24)) } interface Invariant { ->Invariant : Symbol(Invariant, Decl(conditionalTypes2.ts, 8, 1)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 10, 20)) +>Invariant : Symbol(Invariant, Decl(conditionalTypes2.ts, 6, 1)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 8, 20)) foo: T extends string ? keyof T : T; ->foo : Symbol(Invariant.foo, Decl(conditionalTypes2.ts, 10, 24)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 10, 20)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 10, 20)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 10, 20)) +>foo : Symbol(Invariant.foo, Decl(conditionalTypes2.ts, 8, 24)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 8, 20)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 8, 20)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 8, 20)) } function f1(a: Covariant, b: Covariant) { ->f1 : Symbol(f1, Decl(conditionalTypes2.ts, 12, 1)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 14, 12)) ->B : Symbol(B, Decl(conditionalTypes2.ts, 14, 14)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 14, 12)) ->a : Symbol(a, Decl(conditionalTypes2.ts, 14, 28)) +>f1 : Symbol(f1, Decl(conditionalTypes2.ts, 10, 1)) +>A : Symbol(A, Decl(conditionalTypes2.ts, 12, 12)) +>B : Symbol(B, Decl(conditionalTypes2.ts, 12, 14)) +>A : Symbol(A, Decl(conditionalTypes2.ts, 12, 12)) +>a : Symbol(a, Decl(conditionalTypes2.ts, 12, 28)) >Covariant : Symbol(Covariant, Decl(conditionalTypes2.ts, 0, 0)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 14, 12)) ->b : Symbol(b, Decl(conditionalTypes2.ts, 14, 44)) +>A : Symbol(A, Decl(conditionalTypes2.ts, 12, 12)) +>b : Symbol(b, Decl(conditionalTypes2.ts, 12, 44)) >Covariant : Symbol(Covariant, Decl(conditionalTypes2.ts, 0, 0)) ->B : Symbol(B, Decl(conditionalTypes2.ts, 14, 14)) +>B : Symbol(B, Decl(conditionalTypes2.ts, 12, 14)) - a = b; // Error ->a : Symbol(a, Decl(conditionalTypes2.ts, 14, 28)) ->b : Symbol(b, Decl(conditionalTypes2.ts, 14, 44)) + a = b; +>a : Symbol(a, Decl(conditionalTypes2.ts, 12, 28)) +>b : Symbol(b, Decl(conditionalTypes2.ts, 12, 44)) b = a; // Error ->b : Symbol(b, Decl(conditionalTypes2.ts, 14, 44)) ->a : Symbol(a, Decl(conditionalTypes2.ts, 14, 28)) +>b : Symbol(b, Decl(conditionalTypes2.ts, 12, 44)) +>a : Symbol(a, Decl(conditionalTypes2.ts, 12, 28)) } function f2(a: Contravariant, b: Contravariant) { ->f2 : Symbol(f2, Decl(conditionalTypes2.ts, 17, 1)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 19, 12)) ->B : Symbol(B, Decl(conditionalTypes2.ts, 19, 14)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 19, 12)) ->a : Symbol(a, Decl(conditionalTypes2.ts, 19, 28)) ->Contravariant : Symbol(Contravariant, Decl(conditionalTypes2.ts, 4, 1)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 19, 12)) ->b : Symbol(b, Decl(conditionalTypes2.ts, 19, 48)) ->Contravariant : Symbol(Contravariant, Decl(conditionalTypes2.ts, 4, 1)) ->B : Symbol(B, Decl(conditionalTypes2.ts, 19, 14)) +>f2 : Symbol(f2, Decl(conditionalTypes2.ts, 15, 1)) +>A : Symbol(A, Decl(conditionalTypes2.ts, 17, 12)) +>B : Symbol(B, Decl(conditionalTypes2.ts, 17, 14)) +>A : Symbol(A, Decl(conditionalTypes2.ts, 17, 12)) +>a : Symbol(a, Decl(conditionalTypes2.ts, 17, 28)) +>Contravariant : Symbol(Contravariant, Decl(conditionalTypes2.ts, 2, 1)) +>A : Symbol(A, Decl(conditionalTypes2.ts, 17, 12)) +>b : Symbol(b, Decl(conditionalTypes2.ts, 17, 48)) +>Contravariant : Symbol(Contravariant, Decl(conditionalTypes2.ts, 2, 1)) +>B : Symbol(B, Decl(conditionalTypes2.ts, 17, 14)) a = b; // Error ->a : Symbol(a, Decl(conditionalTypes2.ts, 19, 28)) ->b : Symbol(b, Decl(conditionalTypes2.ts, 19, 48)) +>a : Symbol(a, Decl(conditionalTypes2.ts, 17, 28)) +>b : Symbol(b, Decl(conditionalTypes2.ts, 17, 48)) - b = a; // Error ->b : Symbol(b, Decl(conditionalTypes2.ts, 19, 48)) ->a : Symbol(a, Decl(conditionalTypes2.ts, 19, 28)) + b = a; +>b : Symbol(b, Decl(conditionalTypes2.ts, 17, 48)) +>a : Symbol(a, Decl(conditionalTypes2.ts, 17, 28)) } function f3(a: Invariant, b: Invariant) { ->f3 : Symbol(f3, Decl(conditionalTypes2.ts, 22, 1)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 24, 12)) ->B : Symbol(B, Decl(conditionalTypes2.ts, 24, 14)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 24, 12)) ->a : Symbol(a, Decl(conditionalTypes2.ts, 24, 28)) ->Invariant : Symbol(Invariant, Decl(conditionalTypes2.ts, 8, 1)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 24, 12)) ->b : Symbol(b, Decl(conditionalTypes2.ts, 24, 44)) ->Invariant : Symbol(Invariant, Decl(conditionalTypes2.ts, 8, 1)) ->B : Symbol(B, Decl(conditionalTypes2.ts, 24, 14)) +>f3 : Symbol(f3, Decl(conditionalTypes2.ts, 20, 1)) +>A : Symbol(A, Decl(conditionalTypes2.ts, 22, 12)) +>B : Symbol(B, Decl(conditionalTypes2.ts, 22, 14)) +>A : Symbol(A, Decl(conditionalTypes2.ts, 22, 12)) +>a : Symbol(a, Decl(conditionalTypes2.ts, 22, 28)) +>Invariant : Symbol(Invariant, Decl(conditionalTypes2.ts, 6, 1)) +>A : Symbol(A, Decl(conditionalTypes2.ts, 22, 12)) +>b : Symbol(b, Decl(conditionalTypes2.ts, 22, 44)) +>Invariant : Symbol(Invariant, Decl(conditionalTypes2.ts, 6, 1)) +>B : Symbol(B, Decl(conditionalTypes2.ts, 22, 14)) a = b; // Error ->a : Symbol(a, Decl(conditionalTypes2.ts, 24, 28)) ->b : Symbol(b, Decl(conditionalTypes2.ts, 24, 44)) +>a : Symbol(a, Decl(conditionalTypes2.ts, 22, 28)) +>b : Symbol(b, Decl(conditionalTypes2.ts, 22, 44)) b = a; // Error ->b : Symbol(b, Decl(conditionalTypes2.ts, 24, 44)) ->a : Symbol(a, Decl(conditionalTypes2.ts, 24, 28)) +>b : Symbol(b, Decl(conditionalTypes2.ts, 22, 44)) +>a : Symbol(a, Decl(conditionalTypes2.ts, 22, 28)) } // Extract is a T that is known to be a Function function isFunction(value: T): value is Extract { ->isFunction : Symbol(isFunction, Decl(conditionalTypes2.ts, 27, 1)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 30, 20)) ->value : Symbol(value, Decl(conditionalTypes2.ts, 30, 23)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 30, 20)) ->value : Symbol(value, Decl(conditionalTypes2.ts, 30, 23)) +>isFunction : Symbol(isFunction, Decl(conditionalTypes2.ts, 25, 1)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 28, 20)) +>value : Symbol(value, Decl(conditionalTypes2.ts, 28, 23)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 28, 20)) +>value : Symbol(value, Decl(conditionalTypes2.ts, 28, 23)) >Extract : Symbol(Extract, Decl(lib.es5.d.ts, --, --)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 30, 20)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 28, 20)) >Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) return typeof value === "function"; ->value : Symbol(value, Decl(conditionalTypes2.ts, 30, 23)) +>value : Symbol(value, Decl(conditionalTypes2.ts, 28, 23)) } function getFunction(item: T) { ->getFunction : Symbol(getFunction, Decl(conditionalTypes2.ts, 32, 1)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 34, 21)) ->item : Symbol(item, Decl(conditionalTypes2.ts, 34, 24)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 34, 21)) +>getFunction : Symbol(getFunction, Decl(conditionalTypes2.ts, 30, 1)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 32, 21)) +>item : Symbol(item, Decl(conditionalTypes2.ts, 32, 24)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 32, 21)) if (isFunction(item)) { ->isFunction : Symbol(isFunction, Decl(conditionalTypes2.ts, 27, 1)) ->item : Symbol(item, Decl(conditionalTypes2.ts, 34, 24)) +>isFunction : Symbol(isFunction, Decl(conditionalTypes2.ts, 25, 1)) +>item : Symbol(item, Decl(conditionalTypes2.ts, 32, 24)) return item; ->item : Symbol(item, Decl(conditionalTypes2.ts, 34, 24)) +>item : Symbol(item, Decl(conditionalTypes2.ts, 32, 24)) } throw new Error(); >Error : Symbol(Error, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) } function f10(x: T) { ->f10 : Symbol(f10, Decl(conditionalTypes2.ts, 39, 1)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 41, 13)) ->x : Symbol(x, Decl(conditionalTypes2.ts, 41, 16)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 41, 13)) +>f10 : Symbol(f10, Decl(conditionalTypes2.ts, 37, 1)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 39, 13)) +>x : Symbol(x, Decl(conditionalTypes2.ts, 39, 16)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 39, 13)) if (isFunction(x)) { ->isFunction : Symbol(isFunction, Decl(conditionalTypes2.ts, 27, 1)) ->x : Symbol(x, Decl(conditionalTypes2.ts, 41, 16)) +>isFunction : Symbol(isFunction, Decl(conditionalTypes2.ts, 25, 1)) +>x : Symbol(x, Decl(conditionalTypes2.ts, 39, 16)) const f: Function = x; ->f : Symbol(f, Decl(conditionalTypes2.ts, 43, 13)) +>f : Symbol(f, Decl(conditionalTypes2.ts, 41, 13)) >Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) ->x : Symbol(x, Decl(conditionalTypes2.ts, 41, 16)) +>x : Symbol(x, Decl(conditionalTypes2.ts, 39, 16)) const t: T = x; ->t : Symbol(t, Decl(conditionalTypes2.ts, 44, 13)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 41, 13)) ->x : Symbol(x, Decl(conditionalTypes2.ts, 41, 16)) +>t : Symbol(t, Decl(conditionalTypes2.ts, 42, 13)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 39, 13)) +>x : Symbol(x, Decl(conditionalTypes2.ts, 39, 16)) } } function f11(x: string | (() => string) | undefined) { ->f11 : Symbol(f11, Decl(conditionalTypes2.ts, 46, 1)) ->x : Symbol(x, Decl(conditionalTypes2.ts, 48, 13)) +>f11 : Symbol(f11, Decl(conditionalTypes2.ts, 44, 1)) +>x : Symbol(x, Decl(conditionalTypes2.ts, 46, 13)) if (isFunction(x)) { ->isFunction : Symbol(isFunction, Decl(conditionalTypes2.ts, 27, 1)) ->x : Symbol(x, Decl(conditionalTypes2.ts, 48, 13)) +>isFunction : Symbol(isFunction, Decl(conditionalTypes2.ts, 25, 1)) +>x : Symbol(x, Decl(conditionalTypes2.ts, 46, 13)) x(); ->x : Symbol(x, Decl(conditionalTypes2.ts, 48, 13)) +>x : Symbol(x, Decl(conditionalTypes2.ts, 46, 13)) } } function f12(x: string | (() => string) | undefined) { ->f12 : Symbol(f12, Decl(conditionalTypes2.ts, 52, 1)) ->x : Symbol(x, Decl(conditionalTypes2.ts, 54, 13)) +>f12 : Symbol(f12, Decl(conditionalTypes2.ts, 50, 1)) +>x : Symbol(x, Decl(conditionalTypes2.ts, 52, 13)) const f = getFunction(x); // () => string ->f : Symbol(f, Decl(conditionalTypes2.ts, 55, 9)) ->getFunction : Symbol(getFunction, Decl(conditionalTypes2.ts, 32, 1)) ->x : Symbol(x, Decl(conditionalTypes2.ts, 54, 13)) +>f : Symbol(f, Decl(conditionalTypes2.ts, 53, 9)) +>getFunction : Symbol(getFunction, Decl(conditionalTypes2.ts, 30, 1)) +>x : Symbol(x, Decl(conditionalTypes2.ts, 52, 13)) f(); ->f : Symbol(f, Decl(conditionalTypes2.ts, 55, 9)) +>f : Symbol(f, Decl(conditionalTypes2.ts, 53, 9)) } type Foo = { foo: string }; ->Foo : Symbol(Foo, Decl(conditionalTypes2.ts, 57, 1)) ->foo : Symbol(foo, Decl(conditionalTypes2.ts, 59, 12)) +>Foo : Symbol(Foo, Decl(conditionalTypes2.ts, 55, 1)) +>foo : Symbol(foo, Decl(conditionalTypes2.ts, 57, 12)) type Bar = { bar: string }; ->Bar : Symbol(Bar, Decl(conditionalTypes2.ts, 59, 27)) ->bar : Symbol(bar, Decl(conditionalTypes2.ts, 60, 12)) +>Bar : Symbol(Bar, Decl(conditionalTypes2.ts, 57, 27)) +>bar : Symbol(bar, Decl(conditionalTypes2.ts, 58, 12)) declare function fooBar(x: { foo: string, bar: string }): void; ->fooBar : Symbol(fooBar, Decl(conditionalTypes2.ts, 60, 27)) ->x : Symbol(x, Decl(conditionalTypes2.ts, 62, 24)) ->foo : Symbol(foo, Decl(conditionalTypes2.ts, 62, 28)) ->bar : Symbol(bar, Decl(conditionalTypes2.ts, 62, 41)) +>fooBar : Symbol(fooBar, Decl(conditionalTypes2.ts, 58, 27)) +>x : Symbol(x, Decl(conditionalTypes2.ts, 60, 24)) +>foo : Symbol(foo, Decl(conditionalTypes2.ts, 60, 28)) +>bar : Symbol(bar, Decl(conditionalTypes2.ts, 60, 41)) declare function fooBat(x: { foo: string, bat: string }): void; ->fooBat : Symbol(fooBat, Decl(conditionalTypes2.ts, 62, 63)) ->x : Symbol(x, Decl(conditionalTypes2.ts, 63, 24)) ->foo : Symbol(foo, Decl(conditionalTypes2.ts, 63, 28)) ->bat : Symbol(bat, Decl(conditionalTypes2.ts, 63, 41)) +>fooBat : Symbol(fooBat, Decl(conditionalTypes2.ts, 60, 63)) +>x : Symbol(x, Decl(conditionalTypes2.ts, 61, 24)) +>foo : Symbol(foo, Decl(conditionalTypes2.ts, 61, 28)) +>bat : Symbol(bat, Decl(conditionalTypes2.ts, 61, 41)) type Extract2 = T extends U ? T extends V ? T : never : never; ->Extract2 : Symbol(Extract2, Decl(conditionalTypes2.ts, 63, 63)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 65, 14)) ->U : Symbol(U, Decl(conditionalTypes2.ts, 65, 16)) ->V : Symbol(V, Decl(conditionalTypes2.ts, 65, 19)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 65, 14)) ->U : Symbol(U, Decl(conditionalTypes2.ts, 65, 16)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 65, 14)) ->V : Symbol(V, Decl(conditionalTypes2.ts, 65, 19)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 65, 14)) +>Extract2 : Symbol(Extract2, Decl(conditionalTypes2.ts, 61, 63)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 63, 14)) +>U : Symbol(U, Decl(conditionalTypes2.ts, 63, 16)) +>V : Symbol(V, Decl(conditionalTypes2.ts, 63, 19)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 63, 14)) +>U : Symbol(U, Decl(conditionalTypes2.ts, 63, 16)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 63, 14)) +>V : Symbol(V, Decl(conditionalTypes2.ts, 63, 19)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 63, 14)) function f20(x: Extract, Bar>, y: Extract, z: Extract2) { ->f20 : Symbol(f20, Decl(conditionalTypes2.ts, 65, 71)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 67, 13)) ->x : Symbol(x, Decl(conditionalTypes2.ts, 67, 16)) +>f20 : Symbol(f20, Decl(conditionalTypes2.ts, 63, 71)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 65, 13)) +>x : Symbol(x, Decl(conditionalTypes2.ts, 65, 16)) >Extract : Symbol(Extract, Decl(lib.es5.d.ts, --, --)) >Extract : Symbol(Extract, Decl(lib.es5.d.ts, --, --)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 67, 13)) ->Foo : Symbol(Foo, Decl(conditionalTypes2.ts, 57, 1)) ->Bar : Symbol(Bar, Decl(conditionalTypes2.ts, 59, 27)) ->y : Symbol(y, Decl(conditionalTypes2.ts, 67, 49)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 65, 13)) +>Foo : Symbol(Foo, Decl(conditionalTypes2.ts, 55, 1)) +>Bar : Symbol(Bar, Decl(conditionalTypes2.ts, 57, 27)) +>y : Symbol(y, Decl(conditionalTypes2.ts, 65, 49)) >Extract : Symbol(Extract, Decl(lib.es5.d.ts, --, --)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 67, 13)) ->Foo : Symbol(Foo, Decl(conditionalTypes2.ts, 57, 1)) ->Bar : Symbol(Bar, Decl(conditionalTypes2.ts, 59, 27)) ->z : Symbol(z, Decl(conditionalTypes2.ts, 67, 75)) ->Extract2 : Symbol(Extract2, Decl(conditionalTypes2.ts, 63, 63)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 67, 13)) ->Foo : Symbol(Foo, Decl(conditionalTypes2.ts, 57, 1)) ->Bar : Symbol(Bar, Decl(conditionalTypes2.ts, 59, 27)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 65, 13)) +>Foo : Symbol(Foo, Decl(conditionalTypes2.ts, 55, 1)) +>Bar : Symbol(Bar, Decl(conditionalTypes2.ts, 57, 27)) +>z : Symbol(z, Decl(conditionalTypes2.ts, 65, 75)) +>Extract2 : Symbol(Extract2, Decl(conditionalTypes2.ts, 61, 63)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 65, 13)) +>Foo : Symbol(Foo, Decl(conditionalTypes2.ts, 55, 1)) +>Bar : Symbol(Bar, Decl(conditionalTypes2.ts, 57, 27)) fooBar(x); ->fooBar : Symbol(fooBar, Decl(conditionalTypes2.ts, 60, 27)) ->x : Symbol(x, Decl(conditionalTypes2.ts, 67, 16)) +>fooBar : Symbol(fooBar, Decl(conditionalTypes2.ts, 58, 27)) +>x : Symbol(x, Decl(conditionalTypes2.ts, 65, 16)) fooBar(y); ->fooBar : Symbol(fooBar, Decl(conditionalTypes2.ts, 60, 27)) ->y : Symbol(y, Decl(conditionalTypes2.ts, 67, 49)) +>fooBar : Symbol(fooBar, Decl(conditionalTypes2.ts, 58, 27)) +>y : Symbol(y, Decl(conditionalTypes2.ts, 65, 49)) fooBar(z); ->fooBar : Symbol(fooBar, Decl(conditionalTypes2.ts, 60, 27)) ->z : Symbol(z, Decl(conditionalTypes2.ts, 67, 75)) +>fooBar : Symbol(fooBar, Decl(conditionalTypes2.ts, 58, 27)) +>z : Symbol(z, Decl(conditionalTypes2.ts, 65, 75)) } function f21(x: Extract, Bar>, y: Extract, z: Extract2) { ->f21 : Symbol(f21, Decl(conditionalTypes2.ts, 71, 1)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 73, 13)) ->x : Symbol(x, Decl(conditionalTypes2.ts, 73, 16)) +>f21 : Symbol(f21, Decl(conditionalTypes2.ts, 69, 1)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 71, 13)) +>x : Symbol(x, Decl(conditionalTypes2.ts, 71, 16)) >Extract : Symbol(Extract, Decl(lib.es5.d.ts, --, --)) >Extract : Symbol(Extract, Decl(lib.es5.d.ts, --, --)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 73, 13)) ->Foo : Symbol(Foo, Decl(conditionalTypes2.ts, 57, 1)) ->Bar : Symbol(Bar, Decl(conditionalTypes2.ts, 59, 27)) ->y : Symbol(y, Decl(conditionalTypes2.ts, 73, 49)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 71, 13)) +>Foo : Symbol(Foo, Decl(conditionalTypes2.ts, 55, 1)) +>Bar : Symbol(Bar, Decl(conditionalTypes2.ts, 57, 27)) +>y : Symbol(y, Decl(conditionalTypes2.ts, 71, 49)) >Extract : Symbol(Extract, Decl(lib.es5.d.ts, --, --)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 73, 13)) ->Foo : Symbol(Foo, Decl(conditionalTypes2.ts, 57, 1)) ->Bar : Symbol(Bar, Decl(conditionalTypes2.ts, 59, 27)) ->z : Symbol(z, Decl(conditionalTypes2.ts, 73, 75)) ->Extract2 : Symbol(Extract2, Decl(conditionalTypes2.ts, 63, 63)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 73, 13)) ->Foo : Symbol(Foo, Decl(conditionalTypes2.ts, 57, 1)) ->Bar : Symbol(Bar, Decl(conditionalTypes2.ts, 59, 27)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 71, 13)) +>Foo : Symbol(Foo, Decl(conditionalTypes2.ts, 55, 1)) +>Bar : Symbol(Bar, Decl(conditionalTypes2.ts, 57, 27)) +>z : Symbol(z, Decl(conditionalTypes2.ts, 71, 75)) +>Extract2 : Symbol(Extract2, Decl(conditionalTypes2.ts, 61, 63)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 71, 13)) +>Foo : Symbol(Foo, Decl(conditionalTypes2.ts, 55, 1)) +>Bar : Symbol(Bar, Decl(conditionalTypes2.ts, 57, 27)) fooBat(x); // Error ->fooBat : Symbol(fooBat, Decl(conditionalTypes2.ts, 62, 63)) ->x : Symbol(x, Decl(conditionalTypes2.ts, 73, 16)) +>fooBat : Symbol(fooBat, Decl(conditionalTypes2.ts, 60, 63)) +>x : Symbol(x, Decl(conditionalTypes2.ts, 71, 16)) fooBat(y); // Error ->fooBat : Symbol(fooBat, Decl(conditionalTypes2.ts, 62, 63)) ->y : Symbol(y, Decl(conditionalTypes2.ts, 73, 49)) +>fooBat : Symbol(fooBat, Decl(conditionalTypes2.ts, 60, 63)) +>y : Symbol(y, Decl(conditionalTypes2.ts, 71, 49)) fooBat(z); // Error ->fooBat : Symbol(fooBat, Decl(conditionalTypes2.ts, 62, 63)) ->z : Symbol(z, Decl(conditionalTypes2.ts, 73, 75)) +>fooBat : Symbol(fooBat, Decl(conditionalTypes2.ts, 60, 63)) +>z : Symbol(z, Decl(conditionalTypes2.ts, 71, 75)) +} + +// Repros from #22860 + +class Opt { +>Opt : Symbol(Opt, Decl(conditionalTypes2.ts, 75, 1)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 79, 10)) + + toVector(): Vector { +>toVector : Symbol(Opt.toVector, Decl(conditionalTypes2.ts, 79, 14)) +>Vector : Symbol(Vector, Decl(conditionalTypes2.ts, 87, 1)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 79, 10)) + + return undefined; +>undefined : Symbol(undefined) + } +} + +interface Seq { +>Seq : Symbol(Seq, Decl(conditionalTypes2.ts, 83, 1)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 85, 14)) + + tail(): Opt>; +>tail : Symbol(Seq.tail, Decl(conditionalTypes2.ts, 85, 18)) +>Opt : Symbol(Opt, Decl(conditionalTypes2.ts, 75, 1)) +>Seq : Symbol(Seq, Decl(conditionalTypes2.ts, 83, 1)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 85, 14)) +} + +class Vector implements Seq { +>Vector : Symbol(Vector, Decl(conditionalTypes2.ts, 87, 1)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 89, 13)) +>Seq : Symbol(Seq, Decl(conditionalTypes2.ts, 83, 1)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 89, 13)) + + tail(): Opt> { +>tail : Symbol(Vector.tail, Decl(conditionalTypes2.ts, 89, 35)) +>Opt : Symbol(Opt, Decl(conditionalTypes2.ts, 75, 1)) +>Vector : Symbol(Vector, Decl(conditionalTypes2.ts, 87, 1)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 89, 13)) + + return undefined; +>undefined : Symbol(undefined) + } + partition2(predicate:(v:T)=>v is U): [Vector,Vector>]; +>partition2 : Symbol(Vector.partition2, Decl(conditionalTypes2.ts, 92, 5), Decl(conditionalTypes2.ts, 93, 88), Decl(conditionalTypes2.ts, 94, 64)) +>U : Symbol(U, Decl(conditionalTypes2.ts, 93, 15)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 89, 13)) +>predicate : Symbol(predicate, Decl(conditionalTypes2.ts, 93, 28)) +>v : Symbol(v, Decl(conditionalTypes2.ts, 93, 39)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 89, 13)) +>v : Symbol(v, Decl(conditionalTypes2.ts, 93, 39)) +>U : Symbol(U, Decl(conditionalTypes2.ts, 93, 15)) +>Vector : Symbol(Vector, Decl(conditionalTypes2.ts, 87, 1)) +>U : Symbol(U, Decl(conditionalTypes2.ts, 93, 15)) +>Vector : Symbol(Vector, Decl(conditionalTypes2.ts, 87, 1)) +>Exclude : Symbol(Exclude, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 89, 13)) +>U : Symbol(U, Decl(conditionalTypes2.ts, 93, 15)) + + partition2(predicate:(x:T)=>boolean): [Vector,Vector]; +>partition2 : Symbol(Vector.partition2, Decl(conditionalTypes2.ts, 92, 5), Decl(conditionalTypes2.ts, 93, 88), Decl(conditionalTypes2.ts, 94, 64)) +>predicate : Symbol(predicate, Decl(conditionalTypes2.ts, 94, 15)) +>x : Symbol(x, Decl(conditionalTypes2.ts, 94, 26)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 89, 13)) +>Vector : Symbol(Vector, Decl(conditionalTypes2.ts, 87, 1)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 89, 13)) +>Vector : Symbol(Vector, Decl(conditionalTypes2.ts, 87, 1)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 89, 13)) + + partition2(predicate:(v:T)=>boolean): [Vector,Vector] { +>partition2 : Symbol(Vector.partition2, Decl(conditionalTypes2.ts, 92, 5), Decl(conditionalTypes2.ts, 93, 88), Decl(conditionalTypes2.ts, 94, 64)) +>U : Symbol(U, Decl(conditionalTypes2.ts, 95, 15)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 89, 13)) +>predicate : Symbol(predicate, Decl(conditionalTypes2.ts, 95, 28)) +>v : Symbol(v, Decl(conditionalTypes2.ts, 95, 39)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 89, 13)) +>Vector : Symbol(Vector, Decl(conditionalTypes2.ts, 87, 1)) +>U : Symbol(U, Decl(conditionalTypes2.ts, 95, 15)) +>Vector : Symbol(Vector, Decl(conditionalTypes2.ts, 87, 1)) + + return undefined; +>undefined : Symbol(undefined) + } +} + +interface A1 { +>A1 : Symbol(A1, Decl(conditionalTypes2.ts, 98, 1)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 100, 13)) + + bat: B1>; +>bat : Symbol(A1.bat, Decl(conditionalTypes2.ts, 100, 17)) +>B1 : Symbol(B1, Decl(conditionalTypes2.ts, 102, 1)) +>A1 : Symbol(A1, Decl(conditionalTypes2.ts, 98, 1)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 100, 13)) +} + +interface B1 extends A1 { +>B1 : Symbol(B1, Decl(conditionalTypes2.ts, 102, 1)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 104, 13)) +>A1 : Symbol(A1, Decl(conditionalTypes2.ts, 98, 1)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 104, 13)) + + bat: B1>; +>bat : Symbol(B1.bat, Decl(conditionalTypes2.ts, 104, 31)) +>B1 : Symbol(B1, Decl(conditionalTypes2.ts, 102, 1)) +>B1 : Symbol(B1, Decl(conditionalTypes2.ts, 102, 1)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 104, 13)) + + boom: T extends any ? true : true +>boom : Symbol(B1.boom, Decl(conditionalTypes2.ts, 105, 19)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 104, 13)) } // Repro from #22899 declare function toString1(value: object | Function): string ; ->toString1 : Symbol(toString1, Decl(conditionalTypes2.ts, 77, 1)) ->value : Symbol(value, Decl(conditionalTypes2.ts, 81, 27)) +>toString1 : Symbol(toString1, Decl(conditionalTypes2.ts, 107, 1)) +>value : Symbol(value, Decl(conditionalTypes2.ts, 111, 27)) >Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) declare function toString2(value: Function): string ; ->toString2 : Symbol(toString2, Decl(conditionalTypes2.ts, 81, 62)) ->value : Symbol(value, Decl(conditionalTypes2.ts, 82, 27)) +>toString2 : Symbol(toString2, Decl(conditionalTypes2.ts, 111, 62)) +>value : Symbol(value, Decl(conditionalTypes2.ts, 112, 27)) >Function : Symbol(Function, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) function foo(value: T) { ->foo : Symbol(foo, Decl(conditionalTypes2.ts, 82, 53)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 84, 13)) ->value : Symbol(value, Decl(conditionalTypes2.ts, 84, 16)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 84, 13)) +>foo : Symbol(foo, Decl(conditionalTypes2.ts, 112, 53)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 114, 13)) +>value : Symbol(value, Decl(conditionalTypes2.ts, 114, 16)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 114, 13)) if (isFunction(value)) { ->isFunction : Symbol(isFunction, Decl(conditionalTypes2.ts, 27, 1)) ->value : Symbol(value, Decl(conditionalTypes2.ts, 84, 16)) +>isFunction : Symbol(isFunction, Decl(conditionalTypes2.ts, 25, 1)) +>value : Symbol(value, Decl(conditionalTypes2.ts, 114, 16)) toString1(value); ->toString1 : Symbol(toString1, Decl(conditionalTypes2.ts, 77, 1)) ->value : Symbol(value, Decl(conditionalTypes2.ts, 84, 16)) +>toString1 : Symbol(toString1, Decl(conditionalTypes2.ts, 107, 1)) +>value : Symbol(value, Decl(conditionalTypes2.ts, 114, 16)) toString2(value); ->toString2 : Symbol(toString2, Decl(conditionalTypes2.ts, 81, 62)) ->value : Symbol(value, Decl(conditionalTypes2.ts, 84, 16)) +>toString2 : Symbol(toString2, Decl(conditionalTypes2.ts, 111, 62)) +>value : Symbol(value, Decl(conditionalTypes2.ts, 114, 16)) } } // Repro from #23052 type A = ->A : Symbol(A, Decl(conditionalTypes2.ts, 89, 1)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 93, 7)) ->V : Symbol(V, Decl(conditionalTypes2.ts, 93, 9)) ->E : Symbol(E, Decl(conditionalTypes2.ts, 93, 12)) +>A : Symbol(A, Decl(conditionalTypes2.ts, 119, 1)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 123, 7)) +>V : Symbol(V, Decl(conditionalTypes2.ts, 123, 9)) +>E : Symbol(E, Decl(conditionalTypes2.ts, 123, 12)) T extends object ->T : Symbol(T, Decl(conditionalTypes2.ts, 93, 7)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 123, 7)) ? { [Q in { [P in keyof T]: T[P] extends V ? P : P; }[keyof T]]: A; } ->Q : Symbol(Q, Decl(conditionalTypes2.ts, 95, 9)) ->P : Symbol(P, Decl(conditionalTypes2.ts, 95, 17)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 93, 7)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 93, 7)) ->P : Symbol(P, Decl(conditionalTypes2.ts, 95, 17)) ->V : Symbol(V, Decl(conditionalTypes2.ts, 93, 9)) ->P : Symbol(P, Decl(conditionalTypes2.ts, 95, 17)) ->P : Symbol(P, Decl(conditionalTypes2.ts, 95, 17)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 93, 7)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 89, 1)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 93, 7)) ->Q : Symbol(Q, Decl(conditionalTypes2.ts, 95, 9)) ->V : Symbol(V, Decl(conditionalTypes2.ts, 93, 9)) ->E : Symbol(E, Decl(conditionalTypes2.ts, 93, 12)) +>Q : Symbol(Q, Decl(conditionalTypes2.ts, 125, 9)) +>P : Symbol(P, Decl(conditionalTypes2.ts, 125, 17)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 123, 7)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 123, 7)) +>P : Symbol(P, Decl(conditionalTypes2.ts, 125, 17)) +>V : Symbol(V, Decl(conditionalTypes2.ts, 123, 9)) +>P : Symbol(P, Decl(conditionalTypes2.ts, 125, 17)) +>P : Symbol(P, Decl(conditionalTypes2.ts, 125, 17)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 123, 7)) +>A : Symbol(A, Decl(conditionalTypes2.ts, 119, 1)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 123, 7)) +>Q : Symbol(Q, Decl(conditionalTypes2.ts, 125, 9)) +>V : Symbol(V, Decl(conditionalTypes2.ts, 123, 9)) +>E : Symbol(E, Decl(conditionalTypes2.ts, 123, 12)) : T extends V ? T : never; ->T : Symbol(T, Decl(conditionalTypes2.ts, 93, 7)) ->V : Symbol(V, Decl(conditionalTypes2.ts, 93, 9)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 93, 7)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 123, 7)) +>V : Symbol(V, Decl(conditionalTypes2.ts, 123, 9)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 123, 7)) type B = ->B : Symbol(B, Decl(conditionalTypes2.ts, 96, 30)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 98, 7)) ->V : Symbol(V, Decl(conditionalTypes2.ts, 98, 9)) +>B : Symbol(B, Decl(conditionalTypes2.ts, 126, 30)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 128, 7)) +>V : Symbol(V, Decl(conditionalTypes2.ts, 128, 9)) T extends object ->T : Symbol(T, Decl(conditionalTypes2.ts, 98, 7)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 128, 7)) ? { [Q in { [P in keyof T]: T[P] extends V ? P : P; }[keyof T]]: B; } ->Q : Symbol(Q, Decl(conditionalTypes2.ts, 100, 9)) ->P : Symbol(P, Decl(conditionalTypes2.ts, 100, 17)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 98, 7)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 98, 7)) ->P : Symbol(P, Decl(conditionalTypes2.ts, 100, 17)) ->V : Symbol(V, Decl(conditionalTypes2.ts, 98, 9)) ->P : Symbol(P, Decl(conditionalTypes2.ts, 100, 17)) ->P : Symbol(P, Decl(conditionalTypes2.ts, 100, 17)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 98, 7)) ->B : Symbol(B, Decl(conditionalTypes2.ts, 96, 30)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 98, 7)) ->Q : Symbol(Q, Decl(conditionalTypes2.ts, 100, 9)) ->V : Symbol(V, Decl(conditionalTypes2.ts, 98, 9)) +>Q : Symbol(Q, Decl(conditionalTypes2.ts, 130, 9)) +>P : Symbol(P, Decl(conditionalTypes2.ts, 130, 17)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 128, 7)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 128, 7)) +>P : Symbol(P, Decl(conditionalTypes2.ts, 130, 17)) +>V : Symbol(V, Decl(conditionalTypes2.ts, 128, 9)) +>P : Symbol(P, Decl(conditionalTypes2.ts, 130, 17)) +>P : Symbol(P, Decl(conditionalTypes2.ts, 130, 17)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 128, 7)) +>B : Symbol(B, Decl(conditionalTypes2.ts, 126, 30)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 128, 7)) +>Q : Symbol(Q, Decl(conditionalTypes2.ts, 130, 9)) +>V : Symbol(V, Decl(conditionalTypes2.ts, 128, 9)) : T extends V ? T : never; ->T : Symbol(T, Decl(conditionalTypes2.ts, 98, 7)) ->V : Symbol(V, Decl(conditionalTypes2.ts, 98, 9)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 98, 7)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 128, 7)) +>V : Symbol(V, Decl(conditionalTypes2.ts, 128, 9)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 128, 7)) type C = ->C : Symbol(C, Decl(conditionalTypes2.ts, 101, 30)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 103, 7)) ->V : Symbol(V, Decl(conditionalTypes2.ts, 103, 9)) ->E : Symbol(E, Decl(conditionalTypes2.ts, 103, 12)) +>C : Symbol(C, Decl(conditionalTypes2.ts, 131, 30)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 133, 7)) +>V : Symbol(V, Decl(conditionalTypes2.ts, 133, 9)) +>E : Symbol(E, Decl(conditionalTypes2.ts, 133, 12)) { [Q in { [P in keyof T]: T[P] extends V ? P : P; }[keyof T]]: C; }; ->Q : Symbol(Q, Decl(conditionalTypes2.ts, 104, 5)) ->P : Symbol(P, Decl(conditionalTypes2.ts, 104, 13)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 103, 7)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 103, 7)) ->P : Symbol(P, Decl(conditionalTypes2.ts, 104, 13)) ->V : Symbol(V, Decl(conditionalTypes2.ts, 103, 9)) ->P : Symbol(P, Decl(conditionalTypes2.ts, 104, 13)) ->P : Symbol(P, Decl(conditionalTypes2.ts, 104, 13)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 103, 7)) ->C : Symbol(C, Decl(conditionalTypes2.ts, 101, 30)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 103, 7)) ->Q : Symbol(Q, Decl(conditionalTypes2.ts, 104, 5)) ->V : Symbol(V, Decl(conditionalTypes2.ts, 103, 9)) ->E : Symbol(E, Decl(conditionalTypes2.ts, 103, 12)) +>Q : Symbol(Q, Decl(conditionalTypes2.ts, 134, 5)) +>P : Symbol(P, Decl(conditionalTypes2.ts, 134, 13)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 133, 7)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 133, 7)) +>P : Symbol(P, Decl(conditionalTypes2.ts, 134, 13)) +>V : Symbol(V, Decl(conditionalTypes2.ts, 133, 9)) +>P : Symbol(P, Decl(conditionalTypes2.ts, 134, 13)) +>P : Symbol(P, Decl(conditionalTypes2.ts, 134, 13)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 133, 7)) +>C : Symbol(C, Decl(conditionalTypes2.ts, 131, 30)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 133, 7)) +>Q : Symbol(Q, Decl(conditionalTypes2.ts, 134, 5)) +>V : Symbol(V, Decl(conditionalTypes2.ts, 133, 9)) +>E : Symbol(E, Decl(conditionalTypes2.ts, 133, 12)) // Repro from #23100 type A2 = ->A2 : Symbol(A2, Decl(conditionalTypes2.ts, 104, 82)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 108, 8)) ->V : Symbol(V, Decl(conditionalTypes2.ts, 108, 10)) ->E : Symbol(E, Decl(conditionalTypes2.ts, 108, 13)) +>A2 : Symbol(A2, Decl(conditionalTypes2.ts, 134, 82)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 138, 8)) +>V : Symbol(V, Decl(conditionalTypes2.ts, 138, 10)) +>E : Symbol(E, Decl(conditionalTypes2.ts, 138, 13)) T extends object ? T extends any[] ? T : { [Q in keyof T]: A2; } : T; ->T : Symbol(T, Decl(conditionalTypes2.ts, 108, 8)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 108, 8)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 108, 8)) ->Q : Symbol(Q, Decl(conditionalTypes2.ts, 109, 48)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 108, 8)) ->A2 : Symbol(A2, Decl(conditionalTypes2.ts, 104, 82)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 108, 8)) ->Q : Symbol(Q, Decl(conditionalTypes2.ts, 109, 48)) ->V : Symbol(V, Decl(conditionalTypes2.ts, 108, 10)) ->E : Symbol(E, Decl(conditionalTypes2.ts, 108, 13)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 108, 8)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 138, 8)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 138, 8)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 138, 8)) +>Q : Symbol(Q, Decl(conditionalTypes2.ts, 139, 48)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 138, 8)) +>A2 : Symbol(A2, Decl(conditionalTypes2.ts, 134, 82)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 138, 8)) +>Q : Symbol(Q, Decl(conditionalTypes2.ts, 139, 48)) +>V : Symbol(V, Decl(conditionalTypes2.ts, 138, 10)) +>E : Symbol(E, Decl(conditionalTypes2.ts, 138, 13)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 138, 8)) type B2 = ->B2 : Symbol(B2, Decl(conditionalTypes2.ts, 109, 85)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 111, 8)) ->V : Symbol(V, Decl(conditionalTypes2.ts, 111, 10)) +>B2 : Symbol(B2, Decl(conditionalTypes2.ts, 139, 85)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 141, 8)) +>V : Symbol(V, Decl(conditionalTypes2.ts, 141, 10)) T extends object ? T extends any[] ? T : { [Q in keyof T]: B2; } : T; ->T : Symbol(T, Decl(conditionalTypes2.ts, 111, 8)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 111, 8)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 111, 8)) ->Q : Symbol(Q, Decl(conditionalTypes2.ts, 112, 48)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 111, 8)) ->B2 : Symbol(B2, Decl(conditionalTypes2.ts, 109, 85)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 111, 8)) ->Q : Symbol(Q, Decl(conditionalTypes2.ts, 112, 48)) ->V : Symbol(V, Decl(conditionalTypes2.ts, 111, 10)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 111, 8)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 141, 8)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 141, 8)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 141, 8)) +>Q : Symbol(Q, Decl(conditionalTypes2.ts, 142, 48)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 141, 8)) +>B2 : Symbol(B2, Decl(conditionalTypes2.ts, 139, 85)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 141, 8)) +>Q : Symbol(Q, Decl(conditionalTypes2.ts, 142, 48)) +>V : Symbol(V, Decl(conditionalTypes2.ts, 141, 10)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 141, 8)) type C2 = ->C2 : Symbol(C2, Decl(conditionalTypes2.ts, 112, 82)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 114, 8)) ->V : Symbol(V, Decl(conditionalTypes2.ts, 114, 10)) ->E : Symbol(E, Decl(conditionalTypes2.ts, 114, 13)) +>C2 : Symbol(C2, Decl(conditionalTypes2.ts, 142, 82)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 144, 8)) +>V : Symbol(V, Decl(conditionalTypes2.ts, 144, 10)) +>E : Symbol(E, Decl(conditionalTypes2.ts, 144, 13)) T extends object ? { [Q in keyof T]: C2; } : T; ->T : Symbol(T, Decl(conditionalTypes2.ts, 114, 8)) ->Q : Symbol(Q, Decl(conditionalTypes2.ts, 115, 26)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 114, 8)) ->C2 : Symbol(C2, Decl(conditionalTypes2.ts, 112, 82)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 114, 8)) ->Q : Symbol(Q, Decl(conditionalTypes2.ts, 115, 26)) ->V : Symbol(V, Decl(conditionalTypes2.ts, 114, 10)) ->E : Symbol(E, Decl(conditionalTypes2.ts, 114, 13)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 114, 8)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 144, 8)) +>Q : Symbol(Q, Decl(conditionalTypes2.ts, 145, 26)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 144, 8)) +>C2 : Symbol(C2, Decl(conditionalTypes2.ts, 142, 82)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 144, 8)) +>Q : Symbol(Q, Decl(conditionalTypes2.ts, 145, 26)) +>V : Symbol(V, Decl(conditionalTypes2.ts, 144, 10)) +>E : Symbol(E, Decl(conditionalTypes2.ts, 144, 13)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 144, 8)) // Repro from #28654 type MaybeTrue = true extends T["b"] ? "yes" : "no"; ->MaybeTrue : Symbol(MaybeTrue, Decl(conditionalTypes2.ts, 115, 63)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 119, 15)) ->b : Symbol(b, Decl(conditionalTypes2.ts, 119, 26)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 119, 15)) +>MaybeTrue : Symbol(MaybeTrue, Decl(conditionalTypes2.ts, 145, 63)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 149, 15)) +>b : Symbol(b, Decl(conditionalTypes2.ts, 149, 26)) +>T : Symbol(T, Decl(conditionalTypes2.ts, 149, 15)) type T0 = MaybeTrue<{ b: never }> // "no" ->T0 : Symbol(T0, Decl(conditionalTypes2.ts, 119, 78)) ->MaybeTrue : Symbol(MaybeTrue, Decl(conditionalTypes2.ts, 115, 63)) ->b : Symbol(b, Decl(conditionalTypes2.ts, 121, 21)) +>T0 : Symbol(T0, Decl(conditionalTypes2.ts, 149, 78)) +>MaybeTrue : Symbol(MaybeTrue, Decl(conditionalTypes2.ts, 145, 63)) +>b : Symbol(b, Decl(conditionalTypes2.ts, 151, 21)) type T1 = MaybeTrue<{ b: false }>; // "no" ->T1 : Symbol(T1, Decl(conditionalTypes2.ts, 121, 33)) ->MaybeTrue : Symbol(MaybeTrue, Decl(conditionalTypes2.ts, 115, 63)) ->b : Symbol(b, Decl(conditionalTypes2.ts, 122, 21)) +>T1 : Symbol(T1, Decl(conditionalTypes2.ts, 151, 33)) +>MaybeTrue : Symbol(MaybeTrue, Decl(conditionalTypes2.ts, 145, 63)) +>b : Symbol(b, Decl(conditionalTypes2.ts, 152, 21)) type T2 = MaybeTrue<{ b: true }>; // "yes" ->T2 : Symbol(T2, Decl(conditionalTypes2.ts, 122, 34)) ->MaybeTrue : Symbol(MaybeTrue, Decl(conditionalTypes2.ts, 115, 63)) ->b : Symbol(b, Decl(conditionalTypes2.ts, 123, 21)) +>T2 : Symbol(T2, Decl(conditionalTypes2.ts, 152, 34)) +>MaybeTrue : Symbol(MaybeTrue, Decl(conditionalTypes2.ts, 145, 63)) +>b : Symbol(b, Decl(conditionalTypes2.ts, 153, 21)) type T3 = MaybeTrue<{ b: boolean }>; // "yes" ->T3 : Symbol(T3, Decl(conditionalTypes2.ts, 123, 33)) ->MaybeTrue : Symbol(MaybeTrue, Decl(conditionalTypes2.ts, 115, 63)) ->b : Symbol(b, Decl(conditionalTypes2.ts, 124, 21)) +>T3 : Symbol(T3, Decl(conditionalTypes2.ts, 153, 33)) +>MaybeTrue : Symbol(MaybeTrue, Decl(conditionalTypes2.ts, 145, 63)) +>b : Symbol(b, Decl(conditionalTypes2.ts, 154, 21)) // Repro from #28824 type Union = 'a' | 'b'; ->Union : Symbol(Union, Decl(conditionalTypes2.ts, 124, 36)) +>Union : Symbol(Union, Decl(conditionalTypes2.ts, 154, 36)) type Product = { f1: A, f2: B}; ->Product : Symbol(Product, Decl(conditionalTypes2.ts, 128, 23)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 129, 13)) ->Union : Symbol(Union, Decl(conditionalTypes2.ts, 124, 36)) ->B : Symbol(B, Decl(conditionalTypes2.ts, 129, 29)) ->f1 : Symbol(f1, Decl(conditionalTypes2.ts, 129, 36)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 129, 13)) ->f2 : Symbol(f2, Decl(conditionalTypes2.ts, 129, 43)) ->B : Symbol(B, Decl(conditionalTypes2.ts, 129, 29)) +>Product : Symbol(Product, Decl(conditionalTypes2.ts, 158, 23)) +>A : Symbol(A, Decl(conditionalTypes2.ts, 159, 13)) +>Union : Symbol(Union, Decl(conditionalTypes2.ts, 154, 36)) +>B : Symbol(B, Decl(conditionalTypes2.ts, 159, 29)) +>f1 : Symbol(f1, Decl(conditionalTypes2.ts, 159, 36)) +>A : Symbol(A, Decl(conditionalTypes2.ts, 159, 13)) +>f2 : Symbol(f2, Decl(conditionalTypes2.ts, 159, 43)) +>B : Symbol(B, Decl(conditionalTypes2.ts, 159, 29)) type ProductUnion = Product<'a', 0> | Product<'b', 1>; ->ProductUnion : Symbol(ProductUnion, Decl(conditionalTypes2.ts, 129, 51)) ->Product : Symbol(Product, Decl(conditionalTypes2.ts, 128, 23)) ->Product : Symbol(Product, Decl(conditionalTypes2.ts, 128, 23)) +>ProductUnion : Symbol(ProductUnion, Decl(conditionalTypes2.ts, 159, 51)) +>Product : Symbol(Product, Decl(conditionalTypes2.ts, 158, 23)) +>Product : Symbol(Product, Decl(conditionalTypes2.ts, 158, 23)) // {a: "b"; b: "a"} type UnionComplement = { ->UnionComplement : Symbol(UnionComplement, Decl(conditionalTypes2.ts, 130, 54)) +>UnionComplement : Symbol(UnionComplement, Decl(conditionalTypes2.ts, 160, 54)) [K in Union]: Exclude ->K : Symbol(K, Decl(conditionalTypes2.ts, 134, 3)) ->Union : Symbol(Union, Decl(conditionalTypes2.ts, 124, 36)) +>K : Symbol(K, Decl(conditionalTypes2.ts, 164, 3)) +>Union : Symbol(Union, Decl(conditionalTypes2.ts, 154, 36)) >Exclude : Symbol(Exclude, Decl(lib.es5.d.ts, --, --)) ->Union : Symbol(Union, Decl(conditionalTypes2.ts, 124, 36)) ->K : Symbol(K, Decl(conditionalTypes2.ts, 134, 3)) +>Union : Symbol(Union, Decl(conditionalTypes2.ts, 154, 36)) +>K : Symbol(K, Decl(conditionalTypes2.ts, 164, 3)) }; type UCA = UnionComplement['a']; ->UCA : Symbol(UCA, Decl(conditionalTypes2.ts, 135, 2)) ->UnionComplement : Symbol(UnionComplement, Decl(conditionalTypes2.ts, 130, 54)) +>UCA : Symbol(UCA, Decl(conditionalTypes2.ts, 165, 2)) +>UnionComplement : Symbol(UnionComplement, Decl(conditionalTypes2.ts, 160, 54)) type UCB = UnionComplement['b']; ->UCB : Symbol(UCB, Decl(conditionalTypes2.ts, 136, 32)) ->UnionComplement : Symbol(UnionComplement, Decl(conditionalTypes2.ts, 130, 54)) +>UCB : Symbol(UCB, Decl(conditionalTypes2.ts, 166, 32)) +>UnionComplement : Symbol(UnionComplement, Decl(conditionalTypes2.ts, 160, 54)) // {a: "a"; b: "b"} type UnionComplementComplement = { ->UnionComplementComplement : Symbol(UnionComplementComplement, Decl(conditionalTypes2.ts, 137, 32)) +>UnionComplementComplement : Symbol(UnionComplementComplement, Decl(conditionalTypes2.ts, 167, 32)) [K in Union]: Exclude> ->K : Symbol(K, Decl(conditionalTypes2.ts, 141, 3)) ->Union : Symbol(Union, Decl(conditionalTypes2.ts, 124, 36)) +>K : Symbol(K, Decl(conditionalTypes2.ts, 171, 3)) +>Union : Symbol(Union, Decl(conditionalTypes2.ts, 154, 36)) >Exclude : Symbol(Exclude, Decl(lib.es5.d.ts, --, --)) ->Union : Symbol(Union, Decl(conditionalTypes2.ts, 124, 36)) +>Union : Symbol(Union, Decl(conditionalTypes2.ts, 154, 36)) >Exclude : Symbol(Exclude, Decl(lib.es5.d.ts, --, --)) ->Union : Symbol(Union, Decl(conditionalTypes2.ts, 124, 36)) ->K : Symbol(K, Decl(conditionalTypes2.ts, 141, 3)) +>Union : Symbol(Union, Decl(conditionalTypes2.ts, 154, 36)) +>K : Symbol(K, Decl(conditionalTypes2.ts, 171, 3)) }; type UCCA = UnionComplementComplement['a']; ->UCCA : Symbol(UCCA, Decl(conditionalTypes2.ts, 142, 2)) ->UnionComplementComplement : Symbol(UnionComplementComplement, Decl(conditionalTypes2.ts, 137, 32)) +>UCCA : Symbol(UCCA, Decl(conditionalTypes2.ts, 172, 2)) +>UnionComplementComplement : Symbol(UnionComplementComplement, Decl(conditionalTypes2.ts, 167, 32)) type UCCB = UnionComplementComplement['b']; ->UCCB : Symbol(UCCB, Decl(conditionalTypes2.ts, 143, 43)) ->UnionComplementComplement : Symbol(UnionComplementComplement, Decl(conditionalTypes2.ts, 137, 32)) +>UCCB : Symbol(UCCB, Decl(conditionalTypes2.ts, 173, 43)) +>UnionComplementComplement : Symbol(UnionComplementComplement, Decl(conditionalTypes2.ts, 167, 32)) // {a: Product<'b', 1>; b: Product<'a', 0>} type ProductComplement = { ->ProductComplement : Symbol(ProductComplement, Decl(conditionalTypes2.ts, 144, 43)) +>ProductComplement : Symbol(ProductComplement, Decl(conditionalTypes2.ts, 174, 43)) [K in Union]: Exclude ->K : Symbol(K, Decl(conditionalTypes2.ts, 148, 3)) ->Union : Symbol(Union, Decl(conditionalTypes2.ts, 124, 36)) +>K : Symbol(K, Decl(conditionalTypes2.ts, 178, 3)) +>Union : Symbol(Union, Decl(conditionalTypes2.ts, 154, 36)) >Exclude : Symbol(Exclude, Decl(lib.es5.d.ts, --, --)) ->ProductUnion : Symbol(ProductUnion, Decl(conditionalTypes2.ts, 129, 51)) ->f1 : Symbol(f1, Decl(conditionalTypes2.ts, 148, 39)) ->K : Symbol(K, Decl(conditionalTypes2.ts, 148, 3)) +>ProductUnion : Symbol(ProductUnion, Decl(conditionalTypes2.ts, 159, 51)) +>f1 : Symbol(f1, Decl(conditionalTypes2.ts, 178, 39)) +>K : Symbol(K, Decl(conditionalTypes2.ts, 178, 3)) }; type PCA = ProductComplement['a']; ->PCA : Symbol(PCA, Decl(conditionalTypes2.ts, 149, 2)) ->ProductComplement : Symbol(ProductComplement, Decl(conditionalTypes2.ts, 144, 43)) +>PCA : Symbol(PCA, Decl(conditionalTypes2.ts, 179, 2)) +>ProductComplement : Symbol(ProductComplement, Decl(conditionalTypes2.ts, 174, 43)) type PCB = ProductComplement['b']; ->PCB : Symbol(PCB, Decl(conditionalTypes2.ts, 150, 34)) ->ProductComplement : Symbol(ProductComplement, Decl(conditionalTypes2.ts, 144, 43)) +>PCB : Symbol(PCB, Decl(conditionalTypes2.ts, 180, 34)) +>ProductComplement : Symbol(ProductComplement, Decl(conditionalTypes2.ts, 174, 43)) // {a: Product<'a', 0>; b: Product<'b', 1>} type ProductComplementComplement = { ->ProductComplementComplement : Symbol(ProductComplementComplement, Decl(conditionalTypes2.ts, 151, 34)) +>ProductComplementComplement : Symbol(ProductComplementComplement, Decl(conditionalTypes2.ts, 181, 34)) [K in Union]: Exclude> ->K : Symbol(K, Decl(conditionalTypes2.ts, 155, 3)) ->Union : Symbol(Union, Decl(conditionalTypes2.ts, 124, 36)) +>K : Symbol(K, Decl(conditionalTypes2.ts, 185, 3)) +>Union : Symbol(Union, Decl(conditionalTypes2.ts, 154, 36)) >Exclude : Symbol(Exclude, Decl(lib.es5.d.ts, --, --)) ->ProductUnion : Symbol(ProductUnion, Decl(conditionalTypes2.ts, 129, 51)) +>ProductUnion : Symbol(ProductUnion, Decl(conditionalTypes2.ts, 159, 51)) >Exclude : Symbol(Exclude, Decl(lib.es5.d.ts, --, --)) ->ProductUnion : Symbol(ProductUnion, Decl(conditionalTypes2.ts, 129, 51)) ->f1 : Symbol(f1, Decl(conditionalTypes2.ts, 155, 61)) ->K : Symbol(K, Decl(conditionalTypes2.ts, 155, 3)) +>ProductUnion : Symbol(ProductUnion, Decl(conditionalTypes2.ts, 159, 51)) +>f1 : Symbol(f1, Decl(conditionalTypes2.ts, 185, 61)) +>K : Symbol(K, Decl(conditionalTypes2.ts, 185, 3)) }; type PCCA = ProductComplementComplement['a']; ->PCCA : Symbol(PCCA, Decl(conditionalTypes2.ts, 156, 2)) ->ProductComplementComplement : Symbol(ProductComplementComplement, Decl(conditionalTypes2.ts, 151, 34)) +>PCCA : Symbol(PCCA, Decl(conditionalTypes2.ts, 186, 2)) +>ProductComplementComplement : Symbol(ProductComplementComplement, Decl(conditionalTypes2.ts, 181, 34)) type PCCB = ProductComplementComplement['b']; ->PCCB : Symbol(PCCB, Decl(conditionalTypes2.ts, 157, 45)) ->ProductComplementComplement : Symbol(ProductComplementComplement, Decl(conditionalTypes2.ts, 151, 34)) - -// Repros from #27118 - -type MyElement = [A] extends [[infer E]] ? E : never; ->MyElement : Symbol(MyElement, Decl(conditionalTypes2.ts, 158, 45)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 162, 15)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 162, 15)) ->E : Symbol(E, Decl(conditionalTypes2.ts, 162, 39)) ->E : Symbol(E, Decl(conditionalTypes2.ts, 162, 39)) - -function oops(arg: MyElement): MyElement { ->oops : Symbol(oops, Decl(conditionalTypes2.ts, 162, 56)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 163, 14)) ->B : Symbol(B, Decl(conditionalTypes2.ts, 163, 16)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 163, 14)) ->arg : Symbol(arg, Decl(conditionalTypes2.ts, 163, 30)) ->MyElement : Symbol(MyElement, Decl(conditionalTypes2.ts, 158, 45)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 163, 14)) ->MyElement : Symbol(MyElement, Decl(conditionalTypes2.ts, 158, 45)) ->B : Symbol(B, Decl(conditionalTypes2.ts, 163, 16)) - - return arg; // Unsound, should be error ->arg : Symbol(arg, Decl(conditionalTypes2.ts, 163, 30)) -} - -type MyAcceptor = [A] extends [[infer E]] ? (arg: E) => void : never; ->MyAcceptor : Symbol(MyAcceptor, Decl(conditionalTypes2.ts, 165, 1)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 167, 16)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 167, 16)) ->E : Symbol(E, Decl(conditionalTypes2.ts, 167, 40)) ->arg : Symbol(arg, Decl(conditionalTypes2.ts, 167, 48)) ->E : Symbol(E, Decl(conditionalTypes2.ts, 167, 40)) - -function oops2(arg: MyAcceptor): MyAcceptor { ->oops2 : Symbol(oops2, Decl(conditionalTypes2.ts, 167, 72)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 168, 15)) ->B : Symbol(B, Decl(conditionalTypes2.ts, 168, 17)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 168, 15)) ->arg : Symbol(arg, Decl(conditionalTypes2.ts, 168, 31)) ->MyAcceptor : Symbol(MyAcceptor, Decl(conditionalTypes2.ts, 165, 1)) ->B : Symbol(B, Decl(conditionalTypes2.ts, 168, 17)) ->MyAcceptor : Symbol(MyAcceptor, Decl(conditionalTypes2.ts, 165, 1)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 168, 15)) - - return arg; // Unsound, should be error ->arg : Symbol(arg, Decl(conditionalTypes2.ts, 168, 31)) -} - -type Dist = T extends number ? number : string; ->Dist : Symbol(Dist, Decl(conditionalTypes2.ts, 170, 1)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 172, 10)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 172, 10)) - -type Aux = A["a"] extends number ? number : string; ->Aux : Symbol(Aux, Decl(conditionalTypes2.ts, 172, 50)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 173, 9)) ->a : Symbol(a, Decl(conditionalTypes2.ts, 173, 20)) ->A : Symbol(A, Decl(conditionalTypes2.ts, 173, 9)) - -type Nondist = Aux<{a: T}>; ->Nondist : Symbol(Nondist, Decl(conditionalTypes2.ts, 173, 77)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 174, 13)) ->Aux : Symbol(Aux, Decl(conditionalTypes2.ts, 172, 50)) ->a : Symbol(a, Decl(conditionalTypes2.ts, 174, 23)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 174, 13)) - -function oops3(arg: Dist): Nondist { ->oops3 : Symbol(oops3, Decl(conditionalTypes2.ts, 174, 30)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 175, 15)) ->arg : Symbol(arg, Decl(conditionalTypes2.ts, 175, 18)) ->Dist : Symbol(Dist, Decl(conditionalTypes2.ts, 170, 1)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 175, 15)) ->Nondist : Symbol(Nondist, Decl(conditionalTypes2.ts, 173, 77)) ->T : Symbol(T, Decl(conditionalTypes2.ts, 175, 15)) - - return arg; // Unsound, should be error ->arg : Symbol(arg, Decl(conditionalTypes2.ts, 175, 18)) -} +>PCCB : Symbol(PCCB, Decl(conditionalTypes2.ts, 187, 45)) +>ProductComplementComplement : Symbol(ProductComplementComplement, Decl(conditionalTypes2.ts, 181, 34)) diff --git a/tests/baselines/reference/conditionalTypes2.types b/tests/baselines/reference/conditionalTypes2.types index 3cffe6ab48e..aac6ba47475 100644 --- a/tests/baselines/reference/conditionalTypes2.types +++ b/tests/baselines/reference/conditionalTypes2.types @@ -1,6 +1,4 @@ === tests/cases/conformance/types/conditional/conditionalTypes2.ts === -// #27118: Conditional types are now invariant in the check type. - interface Covariant { foo: T extends string ? T : number; >foo : T extends string ? T : number @@ -21,7 +19,7 @@ function f1(a: Covariant, b: Covariant) { >a : Covariant >b : Covariant - a = b; // Error + a = b; >a = b : Covariant >a : Covariant >b : Covariant @@ -42,7 +40,7 @@ function f2(a: Contravariant, b: Contravariant) { >a : Contravariant >b : Contravariant - b = a; // Error + b = a; >b = a : Contravariant >b : Contravariant >a : Contravariant @@ -209,6 +207,71 @@ function f21(x: Extract, Bar>, y: Extract, z: E >z : Extract2 } +// Repros from #22860 + +class Opt { +>Opt : Opt + + toVector(): Vector { +>toVector : () => Vector + + return undefined; +>undefined : any +>undefined : undefined + } +} + +interface Seq { + tail(): Opt>; +>tail : () => Opt> +} + +class Vector implements Seq { +>Vector : Vector + + tail(): Opt> { +>tail : () => Opt> + + return undefined; +>undefined : any +>undefined : undefined + } + partition2(predicate:(v:T)=>v is U): [Vector,Vector>]; +>partition2 : { (predicate: (v: T) => v is U): [Vector, Vector>]; (predicate: (x: T) => boolean): [Vector, Vector]; } +>predicate : (v: T) => v is U +>v : T + + partition2(predicate:(x:T)=>boolean): [Vector,Vector]; +>partition2 : { (predicate: (v: T) => v is U): [Vector, Vector>]; (predicate: (x: T) => boolean): [Vector, Vector]; } +>predicate : (x: T) => boolean +>x : T + + partition2(predicate:(v:T)=>boolean): [Vector,Vector] { +>partition2 : { (predicate: (v: T) => v is U): [Vector, Vector>]; (predicate: (x: T) => boolean): [Vector, Vector]; } +>predicate : (v: T) => boolean +>v : T + + return undefined; +>undefined : any +>undefined : undefined + } +} + +interface A1 { + bat: B1>; +>bat : B1> +} + +interface B1 extends A1 { + bat: B1>; +>bat : B1> + + boom: T extends any ? true : true +>boom : T extends any ? true : true +>true : true +>true : true +} + // Repro from #22899 declare function toString1(value: object | Function): string ; @@ -368,47 +431,3 @@ type PCCA = ProductComplementComplement['a']; type PCCB = ProductComplementComplement['b']; >PCCB : Product<"b", 1> -// Repros from #27118 - -type MyElement = [A] extends [[infer E]] ? E : never; ->MyElement : MyElement - -function oops(arg: MyElement): MyElement { ->oops : (arg: MyElement) => MyElement ->arg : MyElement - - return arg; // Unsound, should be error ->arg : MyElement -} - -type MyAcceptor = [A] extends [[infer E]] ? (arg: E) => void : never; ->MyAcceptor : MyAcceptor ->arg : E - -function oops2(arg: MyAcceptor): MyAcceptor { ->oops2 : (arg: MyAcceptor) => MyAcceptor ->arg : MyAcceptor - - return arg; // Unsound, should be error ->arg : MyAcceptor -} - -type Dist = T extends number ? number : string; ->Dist : Dist - -type Aux = A["a"] extends number ? number : string; ->Aux : Aux ->a : unknown - -type Nondist = Aux<{a: T}>; ->Nondist : Aux<{ a: T; }> ->a : T - -function oops3(arg: Dist): Nondist { ->oops3 : (arg: Dist) => Aux<{ a: T; }> ->arg : Dist - - return arg; // Unsound, should be error ->arg : Dist -} - diff --git a/tests/cases/conformance/types/conditional/conditionalTypes2.ts b/tests/cases/conformance/types/conditional/conditionalTypes2.ts index 5d73c58fe7f..4b65b5ddeb2 100644 --- a/tests/cases/conformance/types/conditional/conditionalTypes2.ts +++ b/tests/cases/conformance/types/conditional/conditionalTypes2.ts @@ -1,8 +1,6 @@ // @strict: true // @declaration: true -// #27118: Conditional types are now invariant in the check type. - interface Covariant { foo: T extends string ? T : number; } @@ -16,13 +14,13 @@ interface Invariant { } function f1(a: Covariant, b: Covariant) { - a = b; // Error + a = b; b = a; // Error } function f2(a: Contravariant, b: Contravariant) { a = b; // Error - b = a; // Error + b = a; } function f3(a: Invariant, b: Invariant) { @@ -80,6 +78,38 @@ function f21(x: Extract, Bar>, y: Extract, z: E fooBat(z); // Error } +// Repros from #22860 + +class Opt { + toVector(): Vector { + return undefined; + } +} + +interface Seq { + tail(): Opt>; +} + +class Vector implements Seq { + tail(): Opt> { + return undefined; + } + partition2(predicate:(v:T)=>v is U): [Vector,Vector>]; + partition2(predicate:(x:T)=>boolean): [Vector,Vector]; + partition2(predicate:(v:T)=>boolean): [Vector,Vector] { + return undefined; + } +} + +interface A1 { + bat: B1>; +} + +interface B1 extends A1 { + bat: B1>; + boom: T extends any ? true : true +} + // Repro from #22899 declare function toString1(value: object | Function): string ; @@ -160,22 +190,3 @@ type ProductComplementComplement = { }; type PCCA = ProductComplementComplement['a']; type PCCB = ProductComplementComplement['b']; - -// Repros from #27118 - -type MyElement = [A] extends [[infer E]] ? E : never; -function oops(arg: MyElement): MyElement { - return arg; // Unsound, should be error -} - -type MyAcceptor = [A] extends [[infer E]] ? (arg: E) => void : never; -function oops2(arg: MyAcceptor): MyAcceptor { - return arg; // Unsound, should be error -} - -type Dist = T extends number ? number : string; -type Aux = A["a"] extends number ? number : string; -type Nondist = Aux<{a: T}>; -function oops3(arg: Dist): Nondist { - return arg; // Unsound, should be error -} From f77b43ca090b1c402859e79a31d54238a478c143 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 27 Feb 2019 12:42:30 -0800 Subject: [PATCH 12/19] Update baselines --- .../reference/conditionalTypes2.errors.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/baselines/reference/conditionalTypes2.errors.txt b/tests/baselines/reference/conditionalTypes2.errors.txt index a1a23b6da18..6cf81cf5730 100644 --- a/tests/baselines/reference/conditionalTypes2.errors.txt +++ b/tests/baselines/reference/conditionalTypes2.errors.txt @@ -8,6 +8,13 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(24,5): error TS23 Type 'keyof B' is not assignable to type 'keyof A'. Type 'string | number | symbol' is not assignable to type 'keyof A'. Type 'string' is not assignable to type 'keyof A'. + Type 'string' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'. + Type 'keyof B' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'. + Type 'string | number | symbol' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'. + Type 'string' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'. + Type 'keyof B' is not assignable to type '"valueOf"'. + Type 'string | number | symbol' is not assignable to type '"valueOf"'. + Type 'string' is not assignable to type '"valueOf"'. tests/cases/conformance/types/conditional/conditionalTypes2.ts(25,5): error TS2322: Type 'Invariant' is not assignable to type 'Invariant'. Types of property 'foo' are incompatible. Type 'A extends string ? keyof A : A' is not assignable to type 'B extends string ? keyof B : B'. @@ -61,6 +68,13 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(75,12): error TS2 !!! error TS2322: Type 'keyof B' is not assignable to type 'keyof A'. !!! error TS2322: Type 'string | number | symbol' is not assignable to type 'keyof A'. !!! error TS2322: Type 'string' is not assignable to type 'keyof A'. +!!! error TS2322: Type 'string' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'. +!!! error TS2322: Type 'keyof B' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'. +!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'. +!!! error TS2322: Type 'string' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'. +!!! error TS2322: Type 'keyof B' is not assignable to type '"valueOf"'. +!!! error TS2322: Type 'string | number | symbol' is not assignable to type '"valueOf"'. +!!! error TS2322: Type 'string' is not assignable to type '"valueOf"'. b = a; // Error ~ !!! error TS2322: Type 'Invariant' is not assignable to type 'Invariant'. From 13c08ab32b0aba3d2580671c9436f7a3d6dd6956 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Wed, 27 Feb 2019 14:12:30 -0800 Subject: [PATCH 13/19] Use identity with the permissive instantation to detect nongenric instances and disable variance probing on nongeneric instances (#29981) * Use identity with the restrictive instantation to detect nongenric instances and disable variance probing on nongeneric instances * Generalize to also include interfaces, add test case, still perform argument comparisons for postive comparisons if possible * Actually accept baselines, lol * Reduce deep nesting limit just a bit so yargs still builds * Handle circular identities in isNonGeneric * Use a simple traversal of the types rather than the restrictive instantiation * Cache the bits using an existing field to further reduce any time nongeneric check takes * Revert to using an existing mapper, use permissive > restrictive * Revert constant change * And revert the comment, too --- src/compiler/checker.ts | 16 +- ...eckInfiniteExpansionTermination.errors.txt | 32 ---- ...nvariantGenericErrorElaboration.errors.txt | 52 ------ .../invariantGenericErrorElaboration.types | 4 +- .../mappedTypeRelationships.errors.txt | 4 - ...alInstantiationsRelatedInBothDirections.js | 18 ++ ...tantiationsRelatedInBothDirections.symbols | 43 +++++ ...nstantiationsRelatedInBothDirections.types | 33 ++++ .../recursiveTypeComparison.errors.txt | 27 --- .../baselines/reference/specedNoStackBlown.js | 47 ++++++ .../reference/specedNoStackBlown.symbols | 158 ++++++++++++++++++ .../reference/specedNoStackBlown.types | 64 +++++++ .../strictFunctionTypesErrors.errors.txt | 16 +- ...derIndexSignatureRelationsAlign.errors.txt | 82 --------- ...eroOrderIndexSignatureRelationsAlign.types | 2 +- ...erIndexSignatureRelationsAlign2.errors.txt | 79 --------- ...alInstantiationsRelatedInBothDirections.ts | 12 ++ tests/cases/compiler/specedNoStackBlown.ts | 35 ++++ 18 files changed, 430 insertions(+), 294 deletions(-) delete mode 100644 tests/baselines/reference/checkInfiniteExpansionTermination.errors.txt delete mode 100644 tests/baselines/reference/invariantGenericErrorElaboration.errors.txt create mode 100644 tests/baselines/reference/nongenericPartialInstantiationsRelatedInBothDirections.js create mode 100644 tests/baselines/reference/nongenericPartialInstantiationsRelatedInBothDirections.symbols create mode 100644 tests/baselines/reference/nongenericPartialInstantiationsRelatedInBothDirections.types delete mode 100644 tests/baselines/reference/recursiveTypeComparison.errors.txt create mode 100644 tests/baselines/reference/specedNoStackBlown.js create mode 100644 tests/baselines/reference/specedNoStackBlown.symbols create mode 100644 tests/baselines/reference/specedNoStackBlown.types delete mode 100644 tests/baselines/reference/varianceProblingAndZeroOrderIndexSignatureRelationsAlign.errors.txt delete mode 100644 tests/baselines/reference/varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.errors.txt create mode 100644 tests/cases/compiler/nongenericPartialInstantiationsRelatedInBothDirections.ts create mode 100644 tests/cases/compiler/specedNoStackBlown.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 80853ca2eaf..247c789577c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -12822,12 +12822,22 @@ namespace ts { } return Ternary.False; + function isNonGeneric(type: Type) { + // If we're already in identity relationship checking, we should use `isRelatedTo` + // to catch the `Maybe` from an excessively deep type (which we then assume means + // that the type could possibly contain a generic) + if (relation === identityRelation) { + return isRelatedTo(type, getPermissiveInstantiation(type)) === Ternary.True; + } + return isTypeIdenticalTo(type, getPermissiveInstantiation(type)); + } + function relateVariances(sourceTypeArguments: ReadonlyArray | undefined, targetTypeArguments: ReadonlyArray | undefined, variances: Variance[]) { if (result = typeArgumentsRelatedTo(sourceTypeArguments, targetTypeArguments, variances, reportErrors)) { return result; } - const isCovariantVoid = targetTypeArguments && hasCovariantVoidArgument(targetTypeArguments, variances); - varianceCheckFailed = !isCovariantVoid; + const allowStructuralFallback = (targetTypeArguments && hasCovariantVoidArgument(targetTypeArguments, variances)) || isNonGeneric(source) || isNonGeneric(target); + varianceCheckFailed = !allowStructuralFallback; // The type arguments did not relate appropriately, but it may be because we have no variance // information (in which case typeArgumentsRelatedTo defaulted to covariance for all type // arguments). It might also be the case that the target type has a 'void' type argument for @@ -12835,7 +12845,7 @@ namespace ts { // (in which case any type argument is permitted on the source side). In those cases we proceed // with a structural comparison. Otherwise, we know for certain the instantiations aren't // related and we can return here. - if (variances !== emptyArray && !isCovariantVoid) { + if (variances !== emptyArray && !allowStructuralFallback) { // In some cases generic types that are covariant in regular type checking mode become // invariant in --strictFunctionTypes mode because one or more type parameters are used in // both co- and contravariant positions. In order to make it easier to diagnose *why* such diff --git a/tests/baselines/reference/checkInfiniteExpansionTermination.errors.txt b/tests/baselines/reference/checkInfiniteExpansionTermination.errors.txt deleted file mode 100644 index 014087ff627..00000000000 --- a/tests/baselines/reference/checkInfiniteExpansionTermination.errors.txt +++ /dev/null @@ -1,32 +0,0 @@ -tests/cases/compiler/checkInfiniteExpansionTermination.ts(16,1): error TS2322: Type 'ISubject' is not assignable to type 'IObservable'. - Types of property 'n' are incompatible. - Type 'IObservable' is not assignable to type 'IObservable'. - Type 'Bar[]' is not assignable to type 'Foo[]'. - Property 'x' is missing in type 'Bar' but required in type 'Foo'. - - -==== tests/cases/compiler/checkInfiniteExpansionTermination.ts (1 errors) ==== - // Regression test for #1002 - // Before fix this code would cause infinite loop - - interface IObservable { - n: IObservable; // Needed, must be T[] - } - - // Needed - interface ISubject extends IObservable { } - - interface Foo { x } - interface Bar { y } - - var values: IObservable; - var values2: ISubject; - values = values2; - ~~~~~~ -!!! error TS2322: Type 'ISubject' is not assignable to type 'IObservable'. -!!! error TS2322: Types of property 'n' are incompatible. -!!! error TS2322: Type 'IObservable' is not assignable to type 'IObservable'. -!!! error TS2322: Type 'Bar[]' is not assignable to type 'Foo[]'. -!!! error TS2322: Property 'x' is missing in type 'Bar' but required in type 'Foo'. -!!! related TS2728 tests/cases/compiler/checkInfiniteExpansionTermination.ts:11:17: 'x' is declared here. - \ No newline at end of file diff --git a/tests/baselines/reference/invariantGenericErrorElaboration.errors.txt b/tests/baselines/reference/invariantGenericErrorElaboration.errors.txt deleted file mode 100644 index 0bd79bcf11d..00000000000 --- a/tests/baselines/reference/invariantGenericErrorElaboration.errors.txt +++ /dev/null @@ -1,52 +0,0 @@ -tests/cases/compiler/invariantGenericErrorElaboration.ts(3,7): error TS2322: Type 'Num' is not assignable to type 'Runtype'. - Types of property 'constraint' are incompatible. - Type 'Constraint' is not assignable to type 'Constraint>'. - Types of property 'constraint' are incompatible. - Type 'Constraint>' is not assignable to type 'Constraint>>'. - Types of property 'constraint' are incompatible. - Type 'Constraint>>' is not assignable to type 'Constraint>>>'. - Type 'Constraint>>' is not assignable to type 'Constraint>'. - Types of property 'underlying' are incompatible. - Type 'Constraint>' is not assignable to type 'Constraint'. -tests/cases/compiler/invariantGenericErrorElaboration.ts(4,19): error TS2322: Type 'Num' is not assignable to type 'Runtype'. - - -==== tests/cases/compiler/invariantGenericErrorElaboration.ts (2 errors) ==== - // Repro from #19746 - - const wat: Runtype = Num; - ~~~ -!!! error TS2322: Type 'Num' is not assignable to type 'Runtype'. -!!! error TS2322: Types of property 'constraint' are incompatible. -!!! error TS2322: Type 'Constraint' is not assignable to type 'Constraint>'. -!!! error TS2322: Types of property 'constraint' are incompatible. -!!! error TS2322: Type 'Constraint>' is not assignable to type 'Constraint>>'. -!!! error TS2322: Types of property 'constraint' are incompatible. -!!! error TS2322: Type 'Constraint>>' is not assignable to type 'Constraint>>>'. -!!! error TS2322: Type 'Constraint>>' is not assignable to type 'Constraint>'. -!!! error TS2322: Types of property 'underlying' are incompatible. -!!! error TS2322: Type 'Constraint>' is not assignable to type 'Constraint'. -!!! related TS2728 tests/cases/compiler/invariantGenericErrorElaboration.ts:12:3: 'tag' is declared here. - const Foo = Obj({ foo: Num }) - ~~~ -!!! error TS2322: Type 'Num' is not assignable to type 'Runtype'. -!!! related TS6501 tests/cases/compiler/invariantGenericErrorElaboration.ts:17:34: The expected type comes from this index signature. - - interface Runtype { - constraint: Constraint - witness: A - } - - interface Num extends Runtype { - tag: 'number' - } - declare const Num: Num - - interface Obj }> extends Runtype<{[K in keyof O]: O[K]['witness'] }> {} - declare function Obj }>(fields: O): Obj; - - interface Constraint> extends Runtype { - underlying: A, - check: (x: A['witness']) => void, - } - \ No newline at end of file diff --git a/tests/baselines/reference/invariantGenericErrorElaboration.types b/tests/baselines/reference/invariantGenericErrorElaboration.types index 7c4bdd46d03..86aec86face 100644 --- a/tests/baselines/reference/invariantGenericErrorElaboration.types +++ b/tests/baselines/reference/invariantGenericErrorElaboration.types @@ -6,8 +6,8 @@ const wat: Runtype = Num; >Num : Num const Foo = Obj({ foo: Num }) ->Foo : any ->Obj({ foo: Num }) : any +>Foo : Obj<{ foo: Num; }> +>Obj({ foo: Num }) : Obj<{ foo: Num; }> >Obj : ; }>(fields: O) => Obj >{ foo: Num } : { foo: Num; } >foo : Num diff --git a/tests/baselines/reference/mappedTypeRelationships.errors.txt b/tests/baselines/reference/mappedTypeRelationships.errors.txt index 3d637654079..60a06e000c2 100644 --- a/tests/baselines/reference/mappedTypeRelationships.errors.txt +++ b/tests/baselines/reference/mappedTypeRelationships.errors.txt @@ -34,9 +34,7 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(66,5): error TS2 tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(66,5): error TS2542: Index signature in type 'Readonly' only permits reading. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(72,5): error TS2322: Type 'Partial' is not assignable to type 'T'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(78,5): error TS2322: Type 'Partial' is not assignable to type 'Partial'. - Type 'Thing' is not assignable to type 'T'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(88,5): error TS2322: Type 'Readonly' is not assignable to type 'Readonly'. - Type 'Thing' is not assignable to type 'T'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(127,5): error TS2322: Type 'Partial' is not assignable to type 'Identity'. tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(143,5): error TS2322: Type '{ [P in keyof T]: T[P]; }' is not assignable to type '{ [P in keyof T]: U[P]; }'. Type 'T[P]' is not assignable to type 'U[P]'. @@ -199,7 +197,6 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(168,5): error TS y = x; // Error ~ !!! error TS2322: Type 'Partial' is not assignable to type 'Partial'. -!!! error TS2322: Type 'Thing' is not assignable to type 'T'. } function f40(x: T, y: Readonly) { @@ -212,7 +209,6 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(168,5): error TS y = x; // Error ~ !!! error TS2322: Type 'Readonly' is not assignable to type 'Readonly'. -!!! error TS2322: Type 'Thing' is not assignable to type 'T'. } type Item = { diff --git a/tests/baselines/reference/nongenericPartialInstantiationsRelatedInBothDirections.js b/tests/baselines/reference/nongenericPartialInstantiationsRelatedInBothDirections.js new file mode 100644 index 00000000000..630adb92c43 --- /dev/null +++ b/tests/baselines/reference/nongenericPartialInstantiationsRelatedInBothDirections.js @@ -0,0 +1,18 @@ +//// [nongenericPartialInstantiationsRelatedInBothDirections.ts] +interface Foo { + a: number; + b: number; + bar: string; +} +interface ObjectContaining { + new (sample: Partial): Partial +} +declare let cafoo: ObjectContaining<{ a: number, foo: number }>; +declare let cfoo: ObjectContaining; +cfoo = cafoo; +cafoo = cfoo; + + +//// [nongenericPartialInstantiationsRelatedInBothDirections.js] +cfoo = cafoo; +cafoo = cfoo; diff --git a/tests/baselines/reference/nongenericPartialInstantiationsRelatedInBothDirections.symbols b/tests/baselines/reference/nongenericPartialInstantiationsRelatedInBothDirections.symbols new file mode 100644 index 00000000000..ee61fa0fd88 --- /dev/null +++ b/tests/baselines/reference/nongenericPartialInstantiationsRelatedInBothDirections.symbols @@ -0,0 +1,43 @@ +=== tests/cases/compiler/nongenericPartialInstantiationsRelatedInBothDirections.ts === +interface Foo { +>Foo : Symbol(Foo, Decl(nongenericPartialInstantiationsRelatedInBothDirections.ts, 0, 0)) + + a: number; +>a : Symbol(Foo.a, Decl(nongenericPartialInstantiationsRelatedInBothDirections.ts, 0, 15)) + + b: number; +>b : Symbol(Foo.b, Decl(nongenericPartialInstantiationsRelatedInBothDirections.ts, 1, 14)) + + bar: string; +>bar : Symbol(Foo.bar, Decl(nongenericPartialInstantiationsRelatedInBothDirections.ts, 2, 14)) +} +interface ObjectContaining { +>ObjectContaining : Symbol(ObjectContaining, Decl(nongenericPartialInstantiationsRelatedInBothDirections.ts, 4, 1)) +>T : Symbol(T, Decl(nongenericPartialInstantiationsRelatedInBothDirections.ts, 5, 27)) + + new (sample: Partial): Partial +>sample : Symbol(sample, Decl(nongenericPartialInstantiationsRelatedInBothDirections.ts, 6, 7)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(nongenericPartialInstantiationsRelatedInBothDirections.ts, 5, 27)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>T : Symbol(T, Decl(nongenericPartialInstantiationsRelatedInBothDirections.ts, 5, 27)) +} +declare let cafoo: ObjectContaining<{ a: number, foo: number }>; +>cafoo : Symbol(cafoo, Decl(nongenericPartialInstantiationsRelatedInBothDirections.ts, 8, 11)) +>ObjectContaining : Symbol(ObjectContaining, Decl(nongenericPartialInstantiationsRelatedInBothDirections.ts, 4, 1)) +>a : Symbol(a, Decl(nongenericPartialInstantiationsRelatedInBothDirections.ts, 8, 37)) +>foo : Symbol(foo, Decl(nongenericPartialInstantiationsRelatedInBothDirections.ts, 8, 48)) + +declare let cfoo: ObjectContaining; +>cfoo : Symbol(cfoo, Decl(nongenericPartialInstantiationsRelatedInBothDirections.ts, 9, 11)) +>ObjectContaining : Symbol(ObjectContaining, Decl(nongenericPartialInstantiationsRelatedInBothDirections.ts, 4, 1)) +>Foo : Symbol(Foo, Decl(nongenericPartialInstantiationsRelatedInBothDirections.ts, 0, 0)) + +cfoo = cafoo; +>cfoo : Symbol(cfoo, Decl(nongenericPartialInstantiationsRelatedInBothDirections.ts, 9, 11)) +>cafoo : Symbol(cafoo, Decl(nongenericPartialInstantiationsRelatedInBothDirections.ts, 8, 11)) + +cafoo = cfoo; +>cafoo : Symbol(cafoo, Decl(nongenericPartialInstantiationsRelatedInBothDirections.ts, 8, 11)) +>cfoo : Symbol(cfoo, Decl(nongenericPartialInstantiationsRelatedInBothDirections.ts, 9, 11)) + diff --git a/tests/baselines/reference/nongenericPartialInstantiationsRelatedInBothDirections.types b/tests/baselines/reference/nongenericPartialInstantiationsRelatedInBothDirections.types new file mode 100644 index 00000000000..cbce9ce867b --- /dev/null +++ b/tests/baselines/reference/nongenericPartialInstantiationsRelatedInBothDirections.types @@ -0,0 +1,33 @@ +=== tests/cases/compiler/nongenericPartialInstantiationsRelatedInBothDirections.ts === +interface Foo { + a: number; +>a : number + + b: number; +>b : number + + bar: string; +>bar : string +} +interface ObjectContaining { + new (sample: Partial): Partial +>sample : Partial +} +declare let cafoo: ObjectContaining<{ a: number, foo: number }>; +>cafoo : ObjectContaining<{ a: number; foo: number; }> +>a : number +>foo : number + +declare let cfoo: ObjectContaining; +>cfoo : ObjectContaining + +cfoo = cafoo; +>cfoo = cafoo : ObjectContaining<{ a: number; foo: number; }> +>cfoo : ObjectContaining +>cafoo : ObjectContaining<{ a: number; foo: number; }> + +cafoo = cfoo; +>cafoo = cfoo : ObjectContaining +>cafoo : ObjectContaining<{ a: number; foo: number; }> +>cfoo : ObjectContaining + diff --git a/tests/baselines/reference/recursiveTypeComparison.errors.txt b/tests/baselines/reference/recursiveTypeComparison.errors.txt deleted file mode 100644 index f647763b2e2..00000000000 --- a/tests/baselines/reference/recursiveTypeComparison.errors.txt +++ /dev/null @@ -1,27 +0,0 @@ -tests/cases/compiler/recursiveTypeComparison.ts(14,5): error TS2322: Type 'Observable<{}>' is not assignable to type 'Property'. - Types of property 'needThisOne' are incompatible. - Type 'Observable<{}>' is not assignable to type 'Observable'. - Type '{}' is not assignable to type 'number'. - - -==== tests/cases/compiler/recursiveTypeComparison.ts (1 errors) ==== - // Before fix this would take an exceeding long time to complete (#1170) - - interface Observable { - // This member can't be of type T, Property, or Observable - needThisOne: Observable; - // Add more to make it slower - expo1: Property; // 0.31 seconds in check - expo2: Property; // 3.11 seconds - expo3: Property; // 82.28 seconds - } - interface Property extends Observable { } - - var p: Observable<{}>; - var stuck: Property = p; - ~~~~~ -!!! error TS2322: Type 'Observable<{}>' is not assignable to type 'Property'. -!!! error TS2322: Types of property 'needThisOne' are incompatible. -!!! error TS2322: Type 'Observable<{}>' is not assignable to type 'Observable'. -!!! error TS2322: Type '{}' is not assignable to type 'number'. - \ No newline at end of file diff --git a/tests/baselines/reference/specedNoStackBlown.js b/tests/baselines/reference/specedNoStackBlown.js new file mode 100644 index 00000000000..034caf4d7eb --- /dev/null +++ b/tests/baselines/reference/specedNoStackBlown.js @@ -0,0 +1,47 @@ +//// [specedNoStackBlown.ts] +// Type definitions for spected 0.7 +// Project: https://github.com/25th-floor/spected +// Definitions by: Benjamin Makus +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +declare function spected = SpecValue>(spec: SPEC, input: ROOTINPUT): Result; + +type Predicate = (value: INPUT, inputs: ROOTINPUT) => boolean; + +type ErrorMsg = + | (string | number | boolean | symbol | null | undefined | object) + | ((value: INPUT, field: string) => any); + +export type Spec = [Predicate, ErrorMsg]; + +export type SpecArray = Array>; + +export type SpecFunction = [INPUT] extends [ReadonlyArray] + ? (value: INPUT) => ReadonlyArray> + : [INPUT] extends [object] + ? (value: INPUT) => SpecObject + : (value: INPUT) => SpecArray; + +export type SpecObject = Partial<{[key in keyof INPUT]: SpecValue}>; + +export type SpecValue = [INPUT] extends [ReadonlyArray] + ? SpecArray | SpecFunction + : [INPUT] extends [object] + ? SpecArray | SpecFunction | SpecObject + : SpecArray | SpecFunction; + +export type Result = {[key in keyof INPUT]: true | any[] | Result}; + +export default spected; + + +//// [specedNoStackBlown.js] +"use strict"; +// Type definitions for spected 0.7 +// Project: https://github.com/25th-floor/spected +// Definitions by: Benjamin Makus +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 +exports.__esModule = true; +exports["default"] = spected; diff --git a/tests/baselines/reference/specedNoStackBlown.symbols b/tests/baselines/reference/specedNoStackBlown.symbols new file mode 100644 index 00000000000..299e31e9808 --- /dev/null +++ b/tests/baselines/reference/specedNoStackBlown.symbols @@ -0,0 +1,158 @@ +=== tests/cases/compiler/specedNoStackBlown.ts === +// Type definitions for spected 0.7 +// Project: https://github.com/25th-floor/spected +// Definitions by: Benjamin Makus +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +declare function spected = SpecValue>(spec: SPEC, input: ROOTINPUT): Result; +>spected : Symbol(spected, Decl(specedNoStackBlown.ts, 0, 0)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 6, 25)) +>SPEC : Symbol(SPEC, Decl(specedNoStackBlown.ts, 6, 35)) +>SpecValue : Symbol(SpecValue, Decl(specedNoStackBlown.ts, 24, 115)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 6, 25)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 6, 25)) +>SpecValue : Symbol(SpecValue, Decl(specedNoStackBlown.ts, 24, 115)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 6, 25)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 6, 25)) +>spec : Symbol(spec, Decl(specedNoStackBlown.ts, 6, 116)) +>SPEC : Symbol(SPEC, Decl(specedNoStackBlown.ts, 6, 35)) +>input : Symbol(input, Decl(specedNoStackBlown.ts, 6, 127)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 6, 25)) +>Result : Symbol(Result, Decl(specedNoStackBlown.ts, 30, 75)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 6, 25)) +>SPEC : Symbol(SPEC, Decl(specedNoStackBlown.ts, 6, 35)) + +type Predicate = (value: INPUT, inputs: ROOTINPUT) => boolean; +>Predicate : Symbol(Predicate, Decl(specedNoStackBlown.ts, 6, 171)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 8, 15)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 8, 21)) +>value : Symbol(value, Decl(specedNoStackBlown.ts, 8, 36)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 8, 15)) +>inputs : Symbol(inputs, Decl(specedNoStackBlown.ts, 8, 49)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 8, 21)) + +type ErrorMsg = +>ErrorMsg : Symbol(ErrorMsg, Decl(specedNoStackBlown.ts, 8, 80)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 10, 14)) + + | (string | number | boolean | symbol | null | undefined | object) + | ((value: INPUT, field: string) => any); +>value : Symbol(value, Decl(specedNoStackBlown.ts, 12, 8)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 10, 14)) +>field : Symbol(field, Decl(specedNoStackBlown.ts, 12, 21)) + +export type Spec = [Predicate, ErrorMsg]; +>Spec : Symbol(Spec, Decl(specedNoStackBlown.ts, 12, 45)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 14, 17)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 14, 23)) +>Predicate : Symbol(Predicate, Decl(specedNoStackBlown.ts, 6, 171)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 14, 17)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 14, 23)) +>ErrorMsg : Symbol(ErrorMsg, Decl(specedNoStackBlown.ts, 8, 80)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 14, 17)) + +export type SpecArray = Array>; +>SpecArray : Symbol(SpecArray, Decl(specedNoStackBlown.ts, 14, 90)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 16, 22)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 16, 28)) +>Array : Symbol(Array, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --)) +>Spec : Symbol(Spec, Decl(specedNoStackBlown.ts, 12, 45)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 16, 22)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 16, 28)) + +export type SpecFunction = [INPUT] extends [ReadonlyArray] +>SpecFunction : Symbol(SpecFunction, Decl(specedNoStackBlown.ts, 16, 78)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 18, 25)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 18, 31)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 18, 25)) +>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --)) +>U : Symbol(U, Decl(specedNoStackBlown.ts, 18, 87)) + + ? (value: INPUT) => ReadonlyArray> +>value : Symbol(value, Decl(specedNoStackBlown.ts, 19, 7)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 18, 25)) +>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --)) +>SpecArray : Symbol(SpecArray, Decl(specedNoStackBlown.ts, 14, 90)) +>U : Symbol(U, Decl(specedNoStackBlown.ts, 18, 87)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 18, 31)) + + : [INPUT] extends [object] +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 18, 25)) + + ? (value: INPUT) => SpecObject +>value : Symbol(value, Decl(specedNoStackBlown.ts, 21, 11)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 18, 25)) +>SpecObject : Symbol(SpecObject, Decl(specedNoStackBlown.ts, 22, 56)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 18, 25)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 18, 31)) + + : (value: INPUT) => SpecArray; +>value : Symbol(value, Decl(specedNoStackBlown.ts, 22, 11)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 18, 25)) +>SpecArray : Symbol(SpecArray, Decl(specedNoStackBlown.ts, 14, 90)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 18, 25)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 18, 31)) + +export type SpecObject = Partial<{[key in keyof INPUT]: SpecValue}>; +>SpecObject : Symbol(SpecObject, Decl(specedNoStackBlown.ts, 22, 56)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 24, 23)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 24, 29)) +>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --)) +>key : Symbol(key, Decl(specedNoStackBlown.ts, 24, 59)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 24, 23)) +>SpecValue : Symbol(SpecValue, Decl(specedNoStackBlown.ts, 24, 115)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 24, 23)) +>key : Symbol(key, Decl(specedNoStackBlown.ts, 24, 59)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 24, 29)) + +export type SpecValue = [INPUT] extends [ReadonlyArray] +>SpecValue : Symbol(SpecValue, Decl(specedNoStackBlown.ts, 24, 115)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 26, 22)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 26, 28)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 26, 22)) +>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --)) + + ? SpecArray | SpecFunction +>SpecArray : Symbol(SpecArray, Decl(specedNoStackBlown.ts, 14, 90)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 26, 22)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 26, 28)) +>SpecFunction : Symbol(SpecFunction, Decl(specedNoStackBlown.ts, 16, 78)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 26, 22)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 26, 28)) + + : [INPUT] extends [object] +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 26, 22)) + + ? SpecArray | SpecFunction | SpecObject +>SpecArray : Symbol(SpecArray, Decl(specedNoStackBlown.ts, 14, 90)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 26, 22)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 26, 28)) +>SpecFunction : Symbol(SpecFunction, Decl(specedNoStackBlown.ts, 16, 78)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 26, 22)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 26, 28)) +>SpecObject : Symbol(SpecObject, Decl(specedNoStackBlown.ts, 22, 56)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 26, 22)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 26, 28)) + + : SpecArray | SpecFunction; +>SpecArray : Symbol(SpecArray, Decl(specedNoStackBlown.ts, 14, 90)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 26, 22)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 26, 28)) +>SpecFunction : Symbol(SpecFunction, Decl(specedNoStackBlown.ts, 16, 78)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 26, 22)) +>ROOTINPUT : Symbol(ROOTINPUT, Decl(specedNoStackBlown.ts, 26, 28)) + +export type Result = {[key in keyof INPUT]: true | any[] | Result}; +>Result : Symbol(Result, Decl(specedNoStackBlown.ts, 30, 75)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 32, 19)) +>SPEC : Symbol(SPEC, Decl(specedNoStackBlown.ts, 32, 25)) +>key : Symbol(key, Decl(specedNoStackBlown.ts, 32, 36)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 32, 19)) +>Result : Symbol(Result, Decl(specedNoStackBlown.ts, 30, 75)) +>INPUT : Symbol(INPUT, Decl(specedNoStackBlown.ts, 32, 19)) +>key : Symbol(key, Decl(specedNoStackBlown.ts, 32, 36)) + +export default spected; +>spected : Symbol(spected, Decl(specedNoStackBlown.ts, 0, 0)) + diff --git a/tests/baselines/reference/specedNoStackBlown.types b/tests/baselines/reference/specedNoStackBlown.types new file mode 100644 index 00000000000..654f98941df --- /dev/null +++ b/tests/baselines/reference/specedNoStackBlown.types @@ -0,0 +1,64 @@ +=== tests/cases/compiler/specedNoStackBlown.ts === +// Type definitions for spected 0.7 +// Project: https://github.com/25th-floor/spected +// Definitions by: Benjamin Makus +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +declare function spected = SpecValue>(spec: SPEC, input: ROOTINPUT): Result; +>spected : = SpecValue>(spec: SPEC, input: ROOTINPUT) => Result +>spec : SPEC +>input : ROOTINPUT + +type Predicate = (value: INPUT, inputs: ROOTINPUT) => boolean; +>Predicate : Predicate +>value : INPUT +>inputs : ROOTINPUT + +type ErrorMsg = +>ErrorMsg : ErrorMsg + + | (string | number | boolean | symbol | null | undefined | object) +>null : null + + | ((value: INPUT, field: string) => any); +>value : INPUT +>field : string + +export type Spec = [Predicate, ErrorMsg]; +>Spec : [Predicate, ErrorMsg] + +export type SpecArray = Array>; +>SpecArray : [Predicate, ErrorMsg][] + +export type SpecFunction = [INPUT] extends [ReadonlyArray] +>SpecFunction : SpecFunction + + ? (value: INPUT) => ReadonlyArray> +>value : INPUT + + : [INPUT] extends [object] + ? (value: INPUT) => SpecObject +>value : INPUT + + : (value: INPUT) => SpecArray; +>value : INPUT + +export type SpecObject = Partial<{[key in keyof INPUT]: SpecValue}>; +>SpecObject : Partial<{ [key in keyof INPUT]: SpecValue; }> + +export type SpecValue = [INPUT] extends [ReadonlyArray] +>SpecValue : SpecValue + + ? SpecArray | SpecFunction + : [INPUT] extends [object] + ? SpecArray | SpecFunction | SpecObject + : SpecArray | SpecFunction; + +export type Result = {[key in keyof INPUT]: true | any[] | Result}; +>Result : Result +>true : true + +export default spected; +>spected : = SpecValue>(spec: SPEC, input: ROOTINPUT) => Result + diff --git a/tests/baselines/reference/strictFunctionTypesErrors.errors.txt b/tests/baselines/reference/strictFunctionTypesErrors.errors.txt index 3ff04c44fb7..d24b88a7a94 100644 --- a/tests/baselines/reference/strictFunctionTypesErrors.errors.txt +++ b/tests/baselines/reference/strictFunctionTypesErrors.errors.txt @@ -62,13 +62,9 @@ tests/cases/compiler/strictFunctionTypesErrors.ts(84,1): error TS2322: Type 'Fun tests/cases/compiler/strictFunctionTypesErrors.ts(111,1): error TS2322: Type 'Comparer2' is not assignable to type 'Comparer2'. Property 'dog' is missing in type 'Animal' but required in type 'Dog'. tests/cases/compiler/strictFunctionTypesErrors.ts(126,1): error TS2322: Type 'Crate' is not assignable to type 'Crate'. - Types of property 'onSetItem' are incompatible. - Type '(item: Dog) => void' is not assignable to type '(item: Animal) => void'. - Types of parameters 'item' and 'item' are incompatible. - Type 'Animal' is not assignable to type 'Dog'. + Type 'Animal' is not assignable to type 'Dog'. tests/cases/compiler/strictFunctionTypesErrors.ts(127,1): error TS2322: Type 'Crate' is not assignable to type 'Crate'. - Types of property 'item' are incompatible. - Type 'Animal' is not assignable to type 'Dog'. + Type 'Animal' is not assignable to type 'Dog'. tests/cases/compiler/strictFunctionTypesErrors.ts(133,1): error TS2322: Type '(f: (x: Dog) => Dog) => void' is not assignable to type '(f: (x: Animal) => Animal) => void'. Types of parameters 'f' and 'f' are incompatible. Type 'Animal' is not assignable to type 'Dog'. @@ -308,15 +304,11 @@ tests/cases/compiler/strictFunctionTypesErrors.ts(155,5): error TS2322: Type '(c animalCrate = dogCrate; // Error ~~~~~~~~~~~ !!! error TS2322: Type 'Crate' is not assignable to type 'Crate'. -!!! error TS2322: Types of property 'onSetItem' are incompatible. -!!! error TS2322: Type '(item: Dog) => void' is not assignable to type '(item: Animal) => void'. -!!! error TS2322: Types of parameters 'item' and 'item' are incompatible. -!!! error TS2322: Type 'Animal' is not assignable to type 'Dog'. +!!! error TS2322: Type 'Animal' is not assignable to type 'Dog'. dogCrate = animalCrate; // Error ~~~~~~~~ !!! error TS2322: Type 'Crate' is not assignable to type 'Crate'. -!!! error TS2322: Types of property 'item' are incompatible. -!!! error TS2322: Type 'Animal' is not assignable to type 'Dog'. +!!! error TS2322: Type 'Animal' is not assignable to type 'Dog'. // Verify that callback parameters are strictly checked diff --git a/tests/baselines/reference/varianceProblingAndZeroOrderIndexSignatureRelationsAlign.errors.txt b/tests/baselines/reference/varianceProblingAndZeroOrderIndexSignatureRelationsAlign.errors.txt deleted file mode 100644 index 47f97958f0d..00000000000 --- a/tests/baselines/reference/varianceProblingAndZeroOrderIndexSignatureRelationsAlign.errors.txt +++ /dev/null @@ -1,82 +0,0 @@ -tests/cases/compiler/varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts(63,6): error TS2345: Argument of type 'NeededInfo>' is not assignable to parameter of type 'NeededInfo<{}>'. - Types of property 'ASchema' are incompatible. - Type 'ToA>' is not assignable to type 'ToA<{}>'. - Type '{}' is not assignable to type 'ToB<{ initialize: any; }>'. -tests/cases/compiler/varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts(66,38): error TS2344: Type 'NeededInfo>' does not satisfy the constraint 'NeededInfo<{}>'. - - -==== tests/cases/compiler/varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts (2 errors) ==== - type Either = Left | Right; - - class Left { - readonly _tag: 'Left' = 'Left' - readonly _A!: A - readonly _L!: L - constructor(readonly value: L) {} - /** The given function is applied if this is a `Right` */ - map(f: (a: A) => B): Either { - return this as any - } - ap(fab: Either B>): Either { - return null as any - } - } - - class Right { - readonly _tag: 'Right' = 'Right' - readonly _A!: A - readonly _L!: L - constructor(readonly value: A) {} - map(f: (a: A) => B): Either { - return new Right(f(this.value)) - } - ap(fab: Either B>): Either { - return null as any; - } - } - - class Type { - readonly _A!: A; - readonly _O!: O; - readonly _I!: I; - constructor( - /** a unique name for this codec */ - readonly name: string, - /** a custom type guard */ - readonly is: (u: unknown) => u is A, - /** succeeds if a value of type I can be decoded to a value of type A */ - readonly validate: (input: I, context: {}[]) => Either<{}[], A>, - /** converts a value of type A to a value of type O */ - readonly encode: (a: A) => O - ) {} - /** a version of `validate` with a default context */ - decode(i: I): Either<{}[], A> { return null as any; } - } - - interface Any extends Type {} - - type TypeOf = C["_A"]; - - type ToB = { [k in keyof S]: TypeOf }; - type ToA = { [k in keyof S]: Type }; - - type NeededInfo = { - ASchema: ToA; - }; - - export type MyInfo = NeededInfo>; - - const tmp1: MyInfo = null!; - function tmp2(n: N) {} - tmp2(tmp1); // uncommenting this line removes a type error from a completely unrelated line ?? - ~~~~ -!!! error TS2345: Argument of type 'NeededInfo>' is not assignable to parameter of type 'NeededInfo<{}>'. -!!! error TS2345: Types of property 'ASchema' are incompatible. -!!! error TS2345: Type 'ToA>' is not assignable to type 'ToA<{}>'. -!!! error TS2345: Type '{}' is not assignable to type 'ToB<{ initialize: any; }>'. -!!! related TS2728 tests/cases/compiler/varianceProblingAndZeroOrderIndexSignatureRelationsAlign.ts:59:39: 'initialize' is declared here. - - class Server {} - export class MyServer extends Server {} // not assignable error at `MyInfo` - ~~~~~~ -!!! error TS2344: Type 'NeededInfo>' does not satisfy the constraint 'NeededInfo<{}>'. \ No newline at end of file diff --git a/tests/baselines/reference/varianceProblingAndZeroOrderIndexSignatureRelationsAlign.types b/tests/baselines/reference/varianceProblingAndZeroOrderIndexSignatureRelationsAlign.types index d360372d5aa..f6342d442ee 100644 --- a/tests/baselines/reference/varianceProblingAndZeroOrderIndexSignatureRelationsAlign.types +++ b/tests/baselines/reference/varianceProblingAndZeroOrderIndexSignatureRelationsAlign.types @@ -155,7 +155,7 @@ function tmp2(n: N) {} >n : N tmp2(tmp1); // uncommenting this line removes a type error from a completely unrelated line ?? ->tmp2(tmp1) : any +>tmp2(tmp1) : void >tmp2 : >(n: N) => void >tmp1 : NeededInfo> diff --git a/tests/baselines/reference/varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.errors.txt b/tests/baselines/reference/varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.errors.txt deleted file mode 100644 index aba1bc1db66..00000000000 --- a/tests/baselines/reference/varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.errors.txt +++ /dev/null @@ -1,79 +0,0 @@ -tests/cases/compiler/varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts(66,38): error TS2344: Type 'NeededInfo>' does not satisfy the constraint 'NeededInfo<{}>'. - Types of property 'ASchema' are incompatible. - Type 'ToA>' is not assignable to type 'ToA<{}>'. - Type '{}' is not assignable to type 'ToB<{ initialize: any; }>'. - - -==== tests/cases/compiler/varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts (1 errors) ==== - type Either = Left | Right; - - class Left { - readonly _tag: 'Left' = 'Left' - readonly _A!: A - readonly _L!: L - constructor(readonly value: L) {} - /** The given function is applied if this is a `Right` */ - map(f: (a: A) => B): Either { - return this as any - } - ap(fab: Either B>): Either { - return null as any - } - } - - class Right { - readonly _tag: 'Right' = 'Right' - readonly _A!: A - readonly _L!: L - constructor(readonly value: A) {} - map(f: (a: A) => B): Either { - return new Right(f(this.value)) - } - ap(fab: Either B>): Either { - return null as any; - } - } - - class Type { - readonly _A!: A; - readonly _O!: O; - readonly _I!: I; - constructor( - /** a unique name for this codec */ - readonly name: string, - /** a custom type guard */ - readonly is: (u: unknown) => u is A, - /** succeeds if a value of type I can be decoded to a value of type A */ - readonly validate: (input: I, context: {}[]) => Either<{}[], A>, - /** converts a value of type A to a value of type O */ - readonly encode: (a: A) => O - ) {} - /** a version of `validate` with a default context */ - decode(i: I): Either<{}[], A> { return null as any; } - } - - interface Any extends Type {} - - type TypeOf = C["_A"]; - - type ToB = { [k in keyof S]: TypeOf }; - type ToA = { [k in keyof S]: Type }; - - type NeededInfo = { - ASchema: ToA; - }; - - export type MyInfo = NeededInfo>; - - const tmp1: MyInfo = null!; - function tmp2(n: N) {} - // tmp2(tmp1); // uncommenting this line removes a type error from a completely unrelated line ?? (see test 1, needs to behave the same) - - class Server {} - export class MyServer extends Server {} // not assignable error at `MyInfo` - ~~~~~~ -!!! error TS2344: Type 'NeededInfo>' does not satisfy the constraint 'NeededInfo<{}>'. -!!! error TS2344: Types of property 'ASchema' are incompatible. -!!! error TS2344: Type 'ToA>' is not assignable to type 'ToA<{}>'. -!!! error TS2344: Type '{}' is not assignable to type 'ToB<{ initialize: any; }>'. -!!! related TS2728 tests/cases/compiler/varianceProblingAndZeroOrderIndexSignatureRelationsAlign2.ts:59:39: 'initialize' is declared here. \ No newline at end of file diff --git a/tests/cases/compiler/nongenericPartialInstantiationsRelatedInBothDirections.ts b/tests/cases/compiler/nongenericPartialInstantiationsRelatedInBothDirections.ts new file mode 100644 index 00000000000..ece5187738c --- /dev/null +++ b/tests/cases/compiler/nongenericPartialInstantiationsRelatedInBothDirections.ts @@ -0,0 +1,12 @@ +interface Foo { + a: number; + b: number; + bar: string; +} +interface ObjectContaining { + new (sample: Partial): Partial +} +declare let cafoo: ObjectContaining<{ a: number, foo: number }>; +declare let cfoo: ObjectContaining; +cfoo = cafoo; +cafoo = cfoo; diff --git a/tests/cases/compiler/specedNoStackBlown.ts b/tests/cases/compiler/specedNoStackBlown.ts new file mode 100644 index 00000000000..9ada3ce1c55 --- /dev/null +++ b/tests/cases/compiler/specedNoStackBlown.ts @@ -0,0 +1,35 @@ +// Type definitions for spected 0.7 +// Project: https://github.com/25th-floor/spected +// Definitions by: Benjamin Makus +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +declare function spected = SpecValue>(spec: SPEC, input: ROOTINPUT): Result; + +type Predicate = (value: INPUT, inputs: ROOTINPUT) => boolean; + +type ErrorMsg = + | (string | number | boolean | symbol | null | undefined | object) + | ((value: INPUT, field: string) => any); + +export type Spec = [Predicate, ErrorMsg]; + +export type SpecArray = Array>; + +export type SpecFunction = [INPUT] extends [ReadonlyArray] + ? (value: INPUT) => ReadonlyArray> + : [INPUT] extends [object] + ? (value: INPUT) => SpecObject + : (value: INPUT) => SpecArray; + +export type SpecObject = Partial<{[key in keyof INPUT]: SpecValue}>; + +export type SpecValue = [INPUT] extends [ReadonlyArray] + ? SpecArray | SpecFunction + : [INPUT] extends [object] + ? SpecArray | SpecFunction | SpecObject + : SpecArray | SpecFunction; + +export type Result = {[key in keyof INPUT]: true | any[] | Result}; + +export default spected; From be2db9db12bd58f02d78f8a906f98f5ee9527663 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 27 Feb 2019 14:14:34 -0800 Subject: [PATCH 14/19] Add globalThis (#29332) * Restore original code from bind-toplevel-this With one or two additional comments * Working in JS, but the symbol is not right. Still need to 1. Make it work in Typescript. 2. Add test (and make them work) for the other uses of GlobalThis: window, globalThis, etc. * Check in TS also; update some tests Lots of tests still fail, but all but 1 change so far has been correct. * Update baselines A couple of tests still fail and need to be fixed. * Handle type references to globalThis The type reference must be `typeof globalThis`. Just `globalThis` will be treated as a value reference in type position -- an error. * Restore former behaviour of implicitThis errors I left the noImplicitThis rule for captured use of global this in an arrow function, even though technically it isn't `any` any more -- it's typeof globalThis. However, you should still use some other method to access globals inside an arrow, because captured-global-this is super confusing there. * Test values with type globalThis I ran into a problem with intersecting `Window & typeof globalThis`: 1. This adds a new index signature to Window, which is probably not desired. In fact, with noImplicitAny, it's not desired on globalThis either I think. 2. Adding this type requires editing TSJS-lib-generator, not this repo. So I added the test cases and will probably update them later, when those two problems are fixed. * Add esnext declaration for globalThis * Switch to symbol-based approach I decided I didn't like the import-type-based approach. Update baselines to reflect the difference. * Do not suggest globals for completions at toplevel * Add tests of element and property access * Look up globalThis using normal resolution globalThis is no longer constructed lazily. Its synthetic Identifier node is also now more realistic. * Update fourslash tests * Add missed fourslash test update * Remove esnext.globalthis.d.ts too * Add chained globalThis self-lookup test * Attempt at making globalThis readonly In progress, had to interrupt for other work. * Add/update tests * Addres PR comments: 1. Add parameter to tryGetThisTypeAt to exclude globalThis. 2. Use combined Module flag instead combining them in-place. 3. SymbolDisplay doesn't print 'module globalThis' for this expressions anymore. --- src/compiler/binder.ts | 9 +- src/compiler/checker.ts | 59 ++++-- src/compiler/diagnosticMessages.json | 2 +- src/compiler/types.ts | 2 +- src/harness/fourslash.ts | 18 +- src/services/completions.ts | 2 +- src/services/symbolDisplay.ts | 2 +- src/testRunner/unittests/tsserver/projects.ts | 3 +- .../reference/assignmentLHSIsValue.symbols | 2 + .../reference/assignmentLHSIsValue.types | 6 +- .../castExpressionParentheses.symbols | 4 + .../reference/castExpressionParentheses.types | 4 +- ...sionThisExpressionAndAliasInGlobal.symbols | 1 + ...lisionThisExpressionAndAliasInGlobal.types | 6 +- ...sExpressionAndAmbientClassInGlobal.symbols | 1 + ...hisExpressionAndAmbientClassInGlobal.types | 6 +- ...hisExpressionAndAmbientVarInGlobal.symbols | 1 + ...nThisExpressionAndAmbientVarInGlobal.types | 6 +- ...sionThisExpressionAndClassInGlobal.symbols | 1 + ...lisionThisExpressionAndClassInGlobal.types | 6 +- ...isionThisExpressionAndEnumInGlobal.symbols | 1 + ...llisionThisExpressionAndEnumInGlobal.types | 6 +- ...nThisExpressionAndFunctionInGlobal.symbols | 1 + ...ionThisExpressionAndFunctionInGlobal.types | 6 +- ...nThisExpressionAndLocalVarInLambda.symbols | 1 + ...ionThisExpressionAndLocalVarInLambda.types | 2 +- ...ionThisExpressionAndModuleInGlobal.symbols | 1 + ...isionThisExpressionAndModuleInGlobal.types | 6 +- ...lisionThisExpressionAndVarInGlobal.symbols | 1 + ...ollisionThisExpressionAndVarInGlobal.types | 6 +- .../reference/commentsInterface.symbols | 6 + .../reference/commentsInterface.types | 12 +- .../compoundAssignmentLHSIsValue.errors.txt | 8 +- .../compoundAssignmentLHSIsValue.symbols | 4 + .../compoundAssignmentLHSIsValue.types | 12 +- ...onentiationAssignmentLHSIsValue.errors.txt | 8 +- ...ExponentiationAssignmentLHSIsValue.symbols | 2 + ...ndExponentiationAssignmentLHSIsValue.types | 6 +- .../computedPropertyNames20_ES5.symbols | 1 + .../computedPropertyNames20_ES5.types | 2 +- .../computedPropertyNames20_ES6.symbols | 1 + .../computedPropertyNames20_ES6.types | 2 +- ...ructorWithIncompleteTypeAnnotation.symbols | 1 + ...structorWithIncompleteTypeAnnotation.types | 2 +- .../emitArrowFunctionThisCapturing.errors.txt | 20 ++ .../emitArrowFunctionThisCapturing.symbols | 7 + .../emitArrowFunctionThisCapturing.types | 6 +- ...itArrowFunctionThisCapturingES6.errors.txt | 20 ++ .../emitArrowFunctionThisCapturingES6.symbols | 7 + .../emitArrowFunctionThisCapturingES6.types | 6 +- ...CapturingThisInTupleDestructuring1.symbols | 3 + ...itCapturingThisInTupleDestructuring1.types | 6 +- .../reference/globalThisCapture.symbols | 3 + .../reference/globalThisCapture.types | 10 +- .../globalThisPropertyAssignment.errors.txt | 13 ++ .../globalThisPropertyAssignment.symbols | 19 ++ .../globalThisPropertyAssignment.types | 28 +++ .../globalThisReadonlyProperties.errors.txt | 15 ++ .../reference/globalThisReadonlyProperties.js | 14 ++ .../globalThisReadonlyProperties.symbols | 22 ++ .../globalThisReadonlyProperties.types | 31 +++ .../reference/globalThisTypeIndexAccess.js | 5 + .../globalThisTypeIndexAccess.symbols | 5 + .../reference/globalThisTypeIndexAccess.types | 5 + .../reference/globalThisUnknown.errors.txt | 20 ++ .../baselines/reference/globalThisUnknown.js | 26 +++ .../reference/globalThisUnknown.symbols | 28 +++ .../reference/globalThisUnknown.types | 39 ++++ .../globalThisUnknownNoImplicitAny.errors.txt | 32 +++ .../globalThisUnknownNoImplicitAny.js | 21 ++ .../globalThisUnknownNoImplicitAny.symbols | 25 +++ .../globalThisUnknownNoImplicitAny.types | 36 ++++ .../globalThisVarDeclaration.errors.txt | 69 ++++++ .../reference/globalThisVarDeclaration.js | 59 ++++++ .../globalThisVarDeclaration.symbols | 87 ++++++++ .../reference/globalThisVarDeclaration.types | 113 ++++++++++ .../reference/implicitAnyInCatch.symbols | 1 + .../reference/implicitAnyInCatch.types | 2 +- ...neJsxFactoryDeclarationsLocalTypes.symbols | 1 + ...lineJsxFactoryDeclarationsLocalTypes.types | 2 +- ...jsxAttributeWithoutExpressionReact.symbols | 1 + .../jsxAttributeWithoutExpressionReact.types | 2 +- .../reference/jsxReactTestSuite.symbols | 5 + .../reference/jsxReactTestSuite.types | 6 +- ...pertyAccessAndArrowFunctionIndent1.symbols | 3 + ...ropertyAccessAndArrowFunctionIndent1.types | 4 +- .../noImplicitThisFunctions.errors.txt | 8 +- .../reference/noImplicitThisFunctions.symbols | 2 + .../reference/noImplicitThisFunctions.types | 10 +- .../parserCommaInTypeMemberList2.symbols | 1 + .../parserCommaInTypeMemberList2.types | 2 +- .../parserConditionalExpression1.symbols | 5 +- .../parserConditionalExpression1.types | 6 +- .../reference/parserForStatement8.errors.txt | 4 +- .../reference/parserForStatement8.symbols | 4 +- .../reference/parserForStatement8.types | 2 +- .../parserModifierOnStatementInBlock2.symbols | 1 + .../parserModifierOnStatementInBlock2.types | 4 +- .../reference/parserStrictMode16.symbols | 11 +- .../reference/parserStrictMode16.types | 2 +- .../parserUnaryExpression1.errors.txt | 4 +- .../reference/parserUnaryExpression1.symbols | 3 +- .../reference/parserUnaryExpression1.types | 2 +- .../reference/propertyWrappedInTry.symbols | 1 + .../reference/propertyWrappedInTry.types | 2 +- .../thisInInvalidContexts.errors.txt | 5 +- .../reference/thisInInvalidContexts.symbols | 1 + .../reference/thisInInvalidContexts.types | 2 +- ...InInvalidContextsExternalModule.errors.txt | 5 +- ...hisInInvalidContextsExternalModule.symbols | 1 + .../thisInInvalidContextsExternalModule.types | 2 +- .../reference/thisTypeInFunctions.symbols | 11 + .../reference/thisTypeInFunctions.types | 40 ++-- .../thisTypeInFunctionsNegative.symbols | 6 + .../thisTypeInFunctionsNegative.types | 12 +- .../reference/topLevelLambda2.symbols | 3 + .../baselines/reference/topLevelLambda2.types | 8 +- .../reference/topLevelLambda3.symbols | 3 + .../baselines/reference/topLevelLambda3.types | 6 +- .../reference/topLevelLambda4.symbols | 3 + .../baselines/reference/topLevelLambda4.types | 10 +- .../reference/topLevelThisAssignment.symbols | 27 ++- .../reference/topLevelThisAssignment.types | 22 +- .../tsxAttributeResolution15.errors.txt | 5 +- .../tsxAttributeResolution15.symbols | 1 + .../reference/tsxAttributeResolution15.types | 2 +- .../tsxSpreadAttributesResolution4.symbols | 1 + .../tsxSpreadAttributesResolution4.types | 2 +- .../typeFromPropertyAssignment23.symbols | 2 + .../typeFromPropertyAssignment23.types | 2 +- .../typeFromPropertyAssignment9.symbols | 5 + .../typeFromPropertyAssignment9.types | 10 +- .../baselines/reference/typeOfThis.errors.txt | 38 +--- tests/baselines/reference/typeOfThis.js | 200 ++++++++---------- tests/baselines/reference/typeOfThis.symbols | 20 +- tests/baselines/reference/typeOfThis.types | 43 ++-- .../reference/unknownSymbols1.symbols | 1 + .../baselines/reference/unknownSymbols1.types | 2 +- .../reference/wrappedIncovations1.symbols | 1 + .../reference/wrappedIncovations1.types | 2 +- .../reference/wrappedIncovations2.symbols | 1 + .../reference/wrappedIncovations2.types | 2 +- .../es2019/globalThisPropertyAssignment.ts | 10 + .../es2019/globalThisReadonlyProperties.ts | 5 + .../es2019/globalThisTypeIndexAccess.ts | 2 + .../conformance/es2019/globalThisUnknown.ts | 13 ++ .../es2019/globalThisUnknownNoImplicitAny.ts | 11 + .../es2019/globalThisVarDeclaration.ts | 35 +++ .../expressions/thisKeyword/typeOfThis.ts | 13 +- .../salsa/topLevelThisAssignment.ts | 1 + .../completionEntryForClassMembers.ts | 1 + .../completionListIsGlobalCompletion.ts | 2 +- .../cases/fourslash/completionListKeywords.ts | 2 +- .../fourslash/completionListWithMeanings.ts | 2 + .../completionListWithModulesFromModule.ts | 4 + .../completionsImport_default_anonymous.ts | 2 +- ...ompletionsImport_exportEquals_anonymous.ts | 4 +- .../fourslash/completionsImport_keywords.ts | 2 +- .../completionsImport_multipleWithSameName.ts | 1 + ...mpletionsImport_named_didNotExistBefore.ts | 1 + ...mpletionsImport_ofAlias_preferShortPath.ts | 1 + .../completionsImport_reExportDefault.ts | 1 + .../completionsImport_shadowedByLocal.ts | 2 +- .../fourslash/completionsTypeKeywords.ts | 2 +- .../cases/fourslash/findAllRefsThisKeyword.ts | 4 +- .../findAllRefsThisKeywordMultipleFiles.ts | 2 +- .../tsxCompletionOnOpeningTagWithoutJSX1.ts | 2 +- 167 files changed, 1372 insertions(+), 400 deletions(-) create mode 100644 tests/baselines/reference/emitArrowFunctionThisCapturing.errors.txt create mode 100644 tests/baselines/reference/emitArrowFunctionThisCapturingES6.errors.txt create mode 100644 tests/baselines/reference/globalThisPropertyAssignment.errors.txt create mode 100644 tests/baselines/reference/globalThisPropertyAssignment.symbols create mode 100644 tests/baselines/reference/globalThisPropertyAssignment.types create mode 100644 tests/baselines/reference/globalThisReadonlyProperties.errors.txt create mode 100644 tests/baselines/reference/globalThisReadonlyProperties.js create mode 100644 tests/baselines/reference/globalThisReadonlyProperties.symbols create mode 100644 tests/baselines/reference/globalThisReadonlyProperties.types create mode 100644 tests/baselines/reference/globalThisTypeIndexAccess.js create mode 100644 tests/baselines/reference/globalThisTypeIndexAccess.symbols create mode 100644 tests/baselines/reference/globalThisTypeIndexAccess.types create mode 100644 tests/baselines/reference/globalThisUnknown.errors.txt create mode 100644 tests/baselines/reference/globalThisUnknown.js create mode 100644 tests/baselines/reference/globalThisUnknown.symbols create mode 100644 tests/baselines/reference/globalThisUnknown.types create mode 100644 tests/baselines/reference/globalThisUnknownNoImplicitAny.errors.txt create mode 100644 tests/baselines/reference/globalThisUnknownNoImplicitAny.js create mode 100644 tests/baselines/reference/globalThisUnknownNoImplicitAny.symbols create mode 100644 tests/baselines/reference/globalThisUnknownNoImplicitAny.types create mode 100644 tests/baselines/reference/globalThisVarDeclaration.errors.txt create mode 100644 tests/baselines/reference/globalThisVarDeclaration.js create mode 100644 tests/baselines/reference/globalThisVarDeclaration.symbols create mode 100644 tests/baselines/reference/globalThisVarDeclaration.types create mode 100644 tests/cases/conformance/es2019/globalThisPropertyAssignment.ts create mode 100644 tests/cases/conformance/es2019/globalThisReadonlyProperties.ts create mode 100644 tests/cases/conformance/es2019/globalThisTypeIndexAccess.ts create mode 100644 tests/cases/conformance/es2019/globalThisUnknown.ts create mode 100644 tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts create mode 100644 tests/cases/conformance/es2019/globalThisVarDeclaration.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 17919a326d5..ed70444bd9b 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -2499,8 +2499,13 @@ namespace ts { declareSymbol(symbolTable, containingClass.symbol, node, SymbolFlags.Property, SymbolFlags.None, /*isReplaceableByMethod*/ true); break; case SyntaxKind.SourceFile: - // this.foo assignment in a source file - // Do not bind. It would be nice to support this someday though. + // this.property = assignment in a source file -- declare symbol in exports for a module, in locals for a script + if ((thisContainer as SourceFile).commonJsModuleIndicator) { + declareSymbol(thisContainer.symbol.exports!, thisContainer.symbol, node, SymbolFlags.Property | SymbolFlags.ExportValue, SymbolFlags.None); + } + else { + declareSymbolAndAddToSymbolTable(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.FunctionScopedVariableExcludes); + } break; default: diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 247c789577c..cf61c4a97a8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -88,8 +88,16 @@ namespace ts { const emitResolver = createResolver(); const nodeBuilder = createNodeBuilder(); + const globals = createSymbolTable(); const undefinedSymbol = createSymbol(SymbolFlags.Property, "undefined" as __String); undefinedSymbol.declarations = []; + + const globalThisSymbol = createSymbol(SymbolFlags.Module, "globalThis" as __String, CheckFlags.Readonly); + globalThisSymbol.exports = globals; + globalThisSymbol.valueDeclaration = createNode(SyntaxKind.Identifier) as Identifier; + (globalThisSymbol.valueDeclaration as Identifier).escapedText = "globalThis" as __String; + globals.set(globalThisSymbol.escapedName, globalThisSymbol); + const argumentsSymbol = createSymbol(SymbolFlags.Property, "arguments" as __String); const requireSymbol = createSymbol(SymbolFlags.Property, "require" as __String); @@ -310,9 +318,9 @@ namespace ts { getAccessibleSymbolChain, getTypePredicateOfSignature: getTypePredicateOfSignature as (signature: Signature) => TypePredicate, // TODO: GH#18217 resolveExternalModuleSymbol, - tryGetThisTypeAt: node => { + tryGetThisTypeAt: (node, includeGlobalThis) => { node = getParseTreeNode(node); - return node && tryGetThisTypeAt(node); + return node && tryGetThisTypeAt(node, includeGlobalThis); }, getTypeArgumentConstraint: nodeIn => { const node = getParseTreeNode(nodeIn, isTypeNode); @@ -459,7 +467,6 @@ namespace ts { const enumNumberIndexInfo = createIndexInfo(stringType, /*isReadonly*/ true); - const globals = createSymbolTable(); interface DuplicateInfoForSymbol { readonly firstFileLocations: Node[]; readonly secondFileLocations: Node[]; @@ -9703,7 +9710,7 @@ namespace ts { } function getLiteralTypeFromProperties(type: Type, include: TypeFlags) { - return getUnionType(map(getPropertiesOfType(type), t => getLiteralTypeFromProperty(t, include))); + return getUnionType(map(getPropertiesOfType(type), p => getLiteralTypeFromProperty(p, include))); } function getNonEnumNumberIndexInfo(type: Type) { @@ -16990,25 +16997,27 @@ namespace ts { captureLexicalThis(node, container); } - const type = tryGetThisTypeAt(node, container); - if (!type && noImplicitThis) { - // With noImplicitThis, functions may not reference 'this' if it has type 'any' - const diag = error( - node, - capturedByArrowFunction && container.kind === SyntaxKind.SourceFile ? - Diagnostics.The_containing_arrow_function_captures_the_global_value_of_this_which_implicitly_has_type_any : - Diagnostics.this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation); - if (!isSourceFile(container)) { - const outsideThis = tryGetThisTypeAt(container); - if (outsideThis) { - addRelatedInfo(diag, createDiagnosticForNode(container, Diagnostics.An_outer_value_of_this_is_shadowed_by_this_container)); + const type = tryGetThisTypeAt(node, /*includeGlobalThis*/ true, container); + if (noImplicitThis) { + const globalThisType = getTypeOfSymbol(globalThisSymbol); + if (type === globalThisType && capturedByArrowFunction) { + error(node, Diagnostics.The_containing_arrow_function_captures_the_global_value_of_this); + } + else if (!type) { + // With noImplicitThis, functions may not reference 'this' if it has type 'any' + const diag = error(node, Diagnostics.this_implicitly_has_type_any_because_it_does_not_have_a_type_annotation); + if (!isSourceFile(container)) { + const outsideThis = tryGetThisTypeAt(container); + if (outsideThis && outsideThis !== globalThisType) { + addRelatedInfo(diag, createDiagnosticForNode(container, Diagnostics.An_outer_value_of_this_is_shadowed_by_this_container)); + } } } } return type || anyType; } - function tryGetThisTypeAt(node: Node, container = getThisContainer(node, /*includeArrowFunctions*/ false)): Type | undefined { + function tryGetThisTypeAt(node: Node, includeGlobalThis = true, container = getThisContainer(node, /*includeArrowFunctions*/ false)): Type | undefined { const isInJS = isInJSFile(node); if (isFunctionLike(container) && (!isInParameterInitializerBeforeContainingFunction(node) || getThisParameter(container))) { @@ -17055,6 +17064,16 @@ namespace ts { return getFlowTypeOfReference(node, type); } } + if (isSourceFile(container)) { + // look up in the source file's locals or exports + if (container.commonJsModuleIndicator) { + const fileSymbol = getSymbolOfNode(container); + return fileSymbol && getTypeOfSymbol(fileSymbol); + } + else if (includeGlobalThis) { + return getTypeOfSymbol(globalThisSymbol); + } + } } function getClassNameFromPrototypeMethod(container: Node) { @@ -19352,6 +19371,12 @@ namespace ts { if (isJSLiteralType(leftType)) { return anyType; } + if (leftType.symbol === globalThisSymbol) { + if (noImplicitAny) { + error(right, Diagnostics.Element_implicitly_has_an_any_type_because_type_0_has_no_index_signature, typeToString(leftType)); + } + return anyType; + } if (right.escapedText && !checkAndReportErrorForExtendingInterface(node)) { reportNonexistentProperty(right, leftType.flags & TypeFlags.TypeParameter && (leftType as TypeParameter).isThisType ? apparentType : leftType); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 09b0f721292..83483a95de1 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -4149,7 +4149,7 @@ "category": "Error", "code": 7040 }, - "The containing arrow function captures the global value of 'this' which implicitly has type 'any'.": { + "The containing arrow function captures the global value of 'this'.": { "category": "Error", "code": 7041 }, diff --git a/src/compiler/types.ts b/src/compiler/types.ts index cce869df44e..42fd1126d4c 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3223,7 +3223,7 @@ namespace ts { */ /* @internal */ resolveExternalModuleSymbol(symbol: Symbol): Symbol; /** @param node A location where we might consider accessing `this`. Not necessarily a ThisExpression. */ - /* @internal */ tryGetThisTypeAt(node: Node): Type | undefined; + /* @internal */ tryGetThisTypeAt(node: Node, includeGlobalThis?: boolean): Type | undefined; /* @internal */ getTypeArgumentConstraint(node: TypeNode): Type | undefined; /** diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index f3a7197e777..16f1a37ae83 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -774,7 +774,7 @@ namespace FourSlash { if ("exact" in options) { ts.Debug.assert(!("includes" in options) && !("excludes" in options)); if (options.exact === undefined) throw this.raiseError("Expected no completions"); - this.verifyCompletionsAreExactly(actualCompletions.entries, toArray(options.exact)); + this.verifyCompletionsAreExactly(actualCompletions.entries, toArray(options.exact), options.marker); } else { if (options.includes) { @@ -841,14 +841,14 @@ namespace FourSlash { } } - private verifyCompletionsAreExactly(actual: ReadonlyArray, expected: ReadonlyArray) { + private verifyCompletionsAreExactly(actual: ReadonlyArray, expected: ReadonlyArray, marker?: ArrayOrSingle) { // First pass: test that names are right. Then we'll test details. - assert.deepEqual(actual.map(a => a.name), expected.map(e => typeof e === "string" ? e : e.name)); + assert.deepEqual(actual.map(a => a.name), expected.map(e => typeof e === "string" ? e : e.name), marker ? "At marker " + JSON.stringify(marker) : undefined); ts.zipWith(actual, expected, (completion, expectedCompletion, index) => { const name = typeof expectedCompletion === "string" ? expectedCompletion : expectedCompletion.name; if (completion.name !== name) { - this.raiseError(`Expected completion at index ${index} to be ${name}, got ${completion.name}`); + this.raiseError(`${marker ? JSON.stringify(marker) : "" } Expected completion at index ${index} to be ${name}, got ${completion.name}`); } this.verifyCompletionEntry(completion, expectedCompletion); }); @@ -4545,6 +4545,7 @@ namespace FourSlashInterface { export function globalTypesPlus(plus: ReadonlyArray): ReadonlyArray { return [ + { name: "globalThis", kind: "module" }, ...globalTypeDecls, ...plus, ...typeKeywords, @@ -4786,6 +4787,7 @@ namespace FourSlashInterface { export const globalsInsideFunction = (plus: ReadonlyArray): ReadonlyArray => [ { name: "arguments", kind: "local var" }, ...plus, + { name: "globalThis", kind: "module" }, ...globalsVars, { name: "undefined", kind: "var" }, ...globalKeywordsInsideFunction, @@ -4921,13 +4923,19 @@ namespace FourSlashInterface { })(); export const globals: ReadonlyArray = [ + { name: "globalThis", kind: "module" }, ...globalsVars, { name: "undefined", kind: "var" }, ...globalKeywords ]; export function globalsPlus(plus: ReadonlyArray): ReadonlyArray { - return [...globalsVars, ...plus, { name: "undefined", kind: "var" }, ...globalKeywords]; + return [ + { name: "globalThis", kind: "module" }, + ...globalsVars, + ...plus, + { name: "undefined", kind: "var" }, + ...globalKeywords]; } } diff --git a/src/services/completions.ts b/src/services/completions.ts index f17ee862cca..a070bf8f7c1 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -1030,7 +1030,7 @@ namespace ts.Completions { // Need to insert 'this.' before properties of `this` type, so only do that if `includeInsertTextCompletions` if (preferences.includeCompletionsWithInsertText && scopeNode.kind !== SyntaxKind.SourceFile) { - const thisType = typeChecker.tryGetThisTypeAt(scopeNode); + const thisType = typeChecker.tryGetThisTypeAt(scopeNode, /*includeGlobalThis*/ false); if (thisType) { for (const symbol of getPropertiesForCompletion(thisType, typeChecker)) { symbolToOriginInfoMap[getSymbolId(symbol)] = { kind: SymbolOriginInfoKind.ThisType }; diff --git a/src/services/symbolDisplay.ts b/src/services/symbolDisplay.ts index e0728f98a29..1c710b8cd78 100644 --- a/src/services/symbolDisplay.ts +++ b/src/services/symbolDisplay.ts @@ -310,7 +310,7 @@ namespace ts.SymbolDisplay { displayParts.push(spacePart()); addFullSymbolName(symbol); } - if (symbolFlags & SymbolFlags.Module) { + if (symbolFlags & SymbolFlags.Module && !isThisExpression) { prefixNextMeaning(); const declaration = getDeclarationOfKind(symbol, SyntaxKind.ModuleDeclaration); const isNamespace = declaration && declaration.name && declaration.name.kind === SyntaxKind.Identifier; diff --git a/src/testRunner/unittests/tsserver/projects.ts b/src/testRunner/unittests/tsserver/projects.ts index 3a648c9189e..264dbff285e 100644 --- a/src/testRunner/unittests/tsserver/projects.ts +++ b/src/testRunner/unittests/tsserver/projects.ts @@ -708,7 +708,8 @@ namespace ts.projectSystem { // Check identifiers defined in HTML content are available in .ts file const project = configuredProjectAt(projectService, 0); let completions = project.getLanguageService().getCompletionsAtPosition(file1.path, 1, emptyOptions); - assert(completions && completions.entries[0].name === "hello", `expected entry hello to be in completion list`); + assert(completions && completions.entries[1].name === "hello", `expected entry hello to be in completion list`); + assert(completions && completions.entries[0].name === "globalThis", `first entry should be globalThis (not strictly relevant for this test).`); // Close HTML file projectService.applyChangesInOpenFiles( diff --git a/tests/baselines/reference/assignmentLHSIsValue.symbols b/tests/baselines/reference/assignmentLHSIsValue.symbols index 17925257dfb..aad2ec2ed95 100644 --- a/tests/baselines/reference/assignmentLHSIsValue.symbols +++ b/tests/baselines/reference/assignmentLHSIsValue.symbols @@ -27,6 +27,7 @@ function foo() { this = value; } >value : Symbol(value, Decl(assignmentLHSIsValue.ts, 1, 3)) this = value; +>this : Symbol(globalThis) >value : Symbol(value, Decl(assignmentLHSIsValue.ts, 1, 3)) // identifiers: module, class, enum, function @@ -116,6 +117,7 @@ foo() = value; // parentheses, the containted expression is value (this) = value; +>this : Symbol(globalThis) >value : Symbol(value, Decl(assignmentLHSIsValue.ts, 1, 3)) (M) = value; diff --git a/tests/baselines/reference/assignmentLHSIsValue.types b/tests/baselines/reference/assignmentLHSIsValue.types index b35c15bfe23..81fd5dc537b 100644 --- a/tests/baselines/reference/assignmentLHSIsValue.types +++ b/tests/baselines/reference/assignmentLHSIsValue.types @@ -33,7 +33,7 @@ function foo() { this = value; } this = value; >this = value : any ->this : any +>this : typeof globalThis >value : any // identifiers: module, class, enum, function @@ -159,8 +159,8 @@ foo() = value; // parentheses, the containted expression is value (this) = value; >(this) = value : any ->(this) : any ->this : any +>(this) : typeof globalThis +>this : typeof globalThis >value : any (M) = value; diff --git a/tests/baselines/reference/castExpressionParentheses.symbols b/tests/baselines/reference/castExpressionParentheses.symbols index df7ef6a1f2f..ebc326e0a85 100644 --- a/tests/baselines/reference/castExpressionParentheses.symbols +++ b/tests/baselines/reference/castExpressionParentheses.symbols @@ -21,7 +21,11 @@ declare var a; (null); // names and dotted names (this); +>this : Symbol(globalThis) + (this.x); +>this : Symbol(globalThis) + ((a).x); >a : Symbol(a, Decl(castExpressionParentheses.ts, 0, 11)) diff --git a/tests/baselines/reference/castExpressionParentheses.types b/tests/baselines/reference/castExpressionParentheses.types index db38aad5a47..a2d789577a0 100644 --- a/tests/baselines/reference/castExpressionParentheses.types +++ b/tests/baselines/reference/castExpressionParentheses.types @@ -77,13 +77,13 @@ declare var a; (this); >(this) : any >this : any ->this : any +>this : typeof globalThis (this.x); >(this.x) : any >this.x : any >this.x : any ->this : any +>this : typeof globalThis >x : any ((a).x); diff --git a/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.symbols b/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.symbols index b8904c087b3..29cb9d44b49 100644 --- a/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.symbols +++ b/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.symbols @@ -7,6 +7,7 @@ module a { } var f = () => this; >f : Symbol(f, Decl(collisionThisExpressionAndAliasInGlobal.ts, 3, 3)) +>this : Symbol(globalThis) import _this = a; // Error >_this : Symbol(_this, Decl(collisionThisExpressionAndAliasInGlobal.ts, 3, 19)) diff --git a/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.types b/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.types index 2bc6c890319..1a4b1c91821 100644 --- a/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.types +++ b/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.types @@ -7,9 +7,9 @@ module a { >10 : 10 } var f = () => this; ->f : () => any ->() => this : () => any ->this : any +>f : () => typeof globalThis +>() => this : () => typeof globalThis +>this : typeof globalThis import _this = a; // Error >_this : typeof a diff --git a/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.symbols b/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.symbols index 71aaa26e2ea..ba225612d73 100644 --- a/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.symbols +++ b/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.symbols @@ -4,6 +4,7 @@ declare class _this { // no error - as no code generation } var f = () => this; >f : Symbol(f, Decl(collisionThisExpressionAndAmbientClassInGlobal.ts, 2, 3)) +>this : Symbol(globalThis) var a = new _this(); // Error >a : Symbol(a, Decl(collisionThisExpressionAndAmbientClassInGlobal.ts, 3, 3)) diff --git a/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.types b/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.types index ea0c8505fa0..886e0c70eea 100644 --- a/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.types +++ b/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.types @@ -3,9 +3,9 @@ declare class _this { // no error - as no code generation >_this : _this } var f = () => this; ->f : () => any ->() => this : () => any ->this : any +>f : () => typeof globalThis +>() => this : () => typeof globalThis +>this : typeof globalThis var a = new _this(); // Error >a : _this diff --git a/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.symbols b/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.symbols index 859234b35fa..702a8300c36 100644 --- a/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.symbols +++ b/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.symbols @@ -4,6 +4,7 @@ declare var _this: number; // no error as no code gen var f = () => this; >f : Symbol(f, Decl(collisionThisExpressionAndAmbientVarInGlobal.ts, 1, 3)) +>this : Symbol(globalThis) _this = 10; // Error >_this : Symbol(_this, Decl(collisionThisExpressionAndAmbientVarInGlobal.ts, 0, 11)) diff --git a/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.types b/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.types index c4038602bba..ed58281dfd6 100644 --- a/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.types +++ b/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.types @@ -3,9 +3,9 @@ declare var _this: number; // no error as no code gen >_this : number var f = () => this; ->f : () => any ->() => this : () => any ->this : any +>f : () => typeof globalThis +>() => this : () => typeof globalThis +>this : typeof globalThis _this = 10; // Error >_this = 10 : 10 diff --git a/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.symbols b/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.symbols index 73781af4894..ba749b89ad0 100644 --- a/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.symbols +++ b/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.symbols @@ -4,4 +4,5 @@ class _this { } var f = () => this; >f : Symbol(f, Decl(collisionThisExpressionAndClassInGlobal.ts, 2, 3)) +>this : Symbol(globalThis) diff --git a/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.types b/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.types index 5e4cd6e0ab4..f68d4212c1f 100644 --- a/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.types +++ b/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.types @@ -3,7 +3,7 @@ class _this { >_this : _this } var f = () => this; ->f : () => any ->() => this : () => any ->this : any +>f : () => typeof globalThis +>() => this : () => typeof globalThis +>this : typeof globalThis diff --git a/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.symbols b/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.symbols index 022b6487d02..88723692ffd 100644 --- a/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.symbols +++ b/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.symbols @@ -10,4 +10,5 @@ enum _this { // Error } var f = () => this; >f : Symbol(f, Decl(collisionThisExpressionAndEnumInGlobal.ts, 4, 3)) +>this : Symbol(globalThis) diff --git a/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.types b/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.types index 87a28ada0e2..5be7877f4e9 100644 --- a/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.types +++ b/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.types @@ -9,7 +9,7 @@ enum _this { // Error >_thisVal2 : _this._thisVal2 } var f = () => this; ->f : () => any ->() => this : () => any ->this : any +>f : () => typeof globalThis +>() => this : () => typeof globalThis +>this : typeof globalThis diff --git a/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.symbols b/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.symbols index a5d171dbe94..5461d86a0fc 100644 --- a/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.symbols +++ b/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.symbols @@ -6,4 +6,5 @@ function _this() { //Error } var f = () => this; >f : Symbol(f, Decl(collisionThisExpressionAndFunctionInGlobal.ts, 3, 3)) +>this : Symbol(globalThis) diff --git a/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.types b/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.types index bb0e11172cc..d3e4b57f58c 100644 --- a/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.types +++ b/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.types @@ -6,7 +6,7 @@ function _this() { //Error >10 : 10 } var f = () => this; ->f : () => any ->() => this : () => any ->this : any +>f : () => typeof globalThis +>() => this : () => typeof globalThis +>this : typeof globalThis diff --git a/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.symbols b/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.symbols index 2105baf09a2..79bfda70d28 100644 --- a/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.symbols +++ b/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.symbols @@ -15,6 +15,7 @@ var x = { return callback(this); >callback : Symbol(callback, Decl(collisionThisExpressionAndLocalVarInLambda.ts, 3, 14)) +>this : Symbol(globalThis) } } alert(x.doStuff(x => alert(x))); diff --git a/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.types b/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.types index cbc625b36e1..d1f051e339c 100644 --- a/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.types +++ b/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.types @@ -20,7 +20,7 @@ var x = { return callback(this); >callback(this) : any >callback : any ->this : any +>this : typeof globalThis } } alert(x.doStuff(x => alert(x))); diff --git a/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.symbols b/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.symbols index 8dcb9dca6d2..8cd392ac268 100644 --- a/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.symbols +++ b/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.symbols @@ -8,4 +8,5 @@ module _this { //Error } var f = () => this; >f : Symbol(f, Decl(collisionThisExpressionAndModuleInGlobal.ts, 4, 3)) +>this : Symbol(globalThis) diff --git a/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.types b/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.types index b950cda2d10..ffa6fcb1a02 100644 --- a/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.types +++ b/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.types @@ -7,7 +7,7 @@ module _this { //Error } } var f = () => this; ->f : () => any ->() => this : () => any ->this : any +>f : () => typeof globalThis +>() => this : () => typeof globalThis +>this : typeof globalThis diff --git a/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.symbols b/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.symbols index 5895e29b2c2..9554f0013f9 100644 --- a/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.symbols +++ b/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.symbols @@ -4,4 +4,5 @@ var _this = 1; var f = () => this; >f : Symbol(f, Decl(collisionThisExpressionAndVarInGlobal.ts, 1, 3)) +>this : Symbol(globalThis) diff --git a/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.types b/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.types index dd12ea63502..a82334edc49 100644 --- a/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.types +++ b/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.types @@ -4,7 +4,7 @@ var _this = 1; >1 : 1 var f = () => this; ->f : () => any ->() => this : () => any ->this : any +>f : () => typeof globalThis +>() => this : () => typeof globalThis +>this : typeof globalThis diff --git a/tests/baselines/reference/commentsInterface.symbols b/tests/baselines/reference/commentsInterface.symbols index 6e3a9e27978..d98dae0c893 100644 --- a/tests/baselines/reference/commentsInterface.symbols +++ b/tests/baselines/reference/commentsInterface.symbols @@ -187,19 +187,25 @@ i3_i = { l: this.f, >l : Symbol(l, Decl(commentsInterface.ts, 56, 56)) +>this : Symbol(globalThis) /** own x*/ x: this.f(10), >x : Symbol(x, Decl(commentsInterface.ts, 57, 14)) +>this : Symbol(globalThis) nc_x: this.l(this.x), >nc_x : Symbol(nc_x, Decl(commentsInterface.ts, 59, 18)) +>this : Symbol(globalThis) +>this : Symbol(globalThis) nc_f: this.f, >nc_f : Symbol(nc_f, Decl(commentsInterface.ts, 60, 25)) +>this : Symbol(globalThis) nc_l: this.l >nc_l : Symbol(nc_l, Decl(commentsInterface.ts, 61, 17)) +>this : Symbol(globalThis) }; i3_i.f(10); diff --git a/tests/baselines/reference/commentsInterface.types b/tests/baselines/reference/commentsInterface.types index 65f1f5f4a38..97169b771d3 100644 --- a/tests/baselines/reference/commentsInterface.types +++ b/tests/baselines/reference/commentsInterface.types @@ -198,7 +198,7 @@ i3_i = { l: this.f, >l : any >this.f : any ->this : any +>this : typeof globalThis >f : any /** own x*/ @@ -206,7 +206,7 @@ i3_i = { >x : any >this.f(10) : any >this.f : any ->this : any +>this : typeof globalThis >f : any >10 : 10 @@ -214,22 +214,22 @@ i3_i = { >nc_x : any >this.l(this.x) : any >this.l : any ->this : any +>this : typeof globalThis >l : any >this.x : any ->this : any +>this : typeof globalThis >x : any nc_f: this.f, >nc_f : any >this.f : any ->this : any +>this : typeof globalThis >f : any nc_l: this.l >nc_l : any >this.l : any ->this : any +>this : typeof globalThis >l : any }; diff --git a/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt b/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt index 8a133148007..2c22361bfd6 100644 --- a/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt +++ b/tests/baselines/reference/compoundAssignmentLHSIsValue.errors.txt @@ -6,7 +6,7 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(16,9): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(21,5): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(22,5): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(25,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(25,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(26,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(30,1): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(31,1): error TS2539: Cannot assign to 'M' because it is not a variable. @@ -45,7 +45,7 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(88,11): error TS1005: ';' expected. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(91,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(92,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. -tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(95,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(95,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(96,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(97,2): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsValue.ts(98,2): error TS2539: Cannot assign to 'M' because it is not a variable. @@ -119,7 +119,7 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa this *= value; ~~~~ -!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. this += value; ~~~~ !!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. @@ -267,7 +267,7 @@ tests/cases/conformance/expressions/assignmentOperator/compoundAssignmentLHSIsVa // parentheses, the containted expression is value (this) *= value; ~~~~~~ -!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. (this) += value; ~~~~~~ !!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. diff --git a/tests/baselines/reference/compoundAssignmentLHSIsValue.symbols b/tests/baselines/reference/compoundAssignmentLHSIsValue.symbols index 790c05ed9a1..891127c32cc 100644 --- a/tests/baselines/reference/compoundAssignmentLHSIsValue.symbols +++ b/tests/baselines/reference/compoundAssignmentLHSIsValue.symbols @@ -51,9 +51,11 @@ function foo() { } this *= value; +>this : Symbol(globalThis) >value : Symbol(value, Decl(compoundAssignmentLHSIsValue.ts, 1, 3)) this += value; +>this : Symbol(globalThis) >value : Symbol(value, Decl(compoundAssignmentLHSIsValue.ts, 1, 3)) // identifiers: module, class, enum, function @@ -216,9 +218,11 @@ foo() += value; // parentheses, the containted expression is value (this) *= value; +>this : Symbol(globalThis) >value : Symbol(value, Decl(compoundAssignmentLHSIsValue.ts, 1, 3)) (this) += value; +>this : Symbol(globalThis) >value : Symbol(value, Decl(compoundAssignmentLHSIsValue.ts, 1, 3)) (M) *= value; diff --git a/tests/baselines/reference/compoundAssignmentLHSIsValue.types b/tests/baselines/reference/compoundAssignmentLHSIsValue.types index 7736256f973..5aafaa2647c 100644 --- a/tests/baselines/reference/compoundAssignmentLHSIsValue.types +++ b/tests/baselines/reference/compoundAssignmentLHSIsValue.types @@ -62,12 +62,12 @@ function foo() { this *= value; >this *= value : number ->this : any +>this : typeof globalThis >value : any this += value; >this += value : any ->this : any +>this : typeof globalThis >value : any // identifiers: module, class, enum, function @@ -300,14 +300,14 @@ foo() += value; // parentheses, the containted expression is value (this) *= value; >(this) *= value : number ->(this) : any ->this : any +>(this) : typeof globalThis +>this : typeof globalThis >value : any (this) += value; >(this) += value : any ->(this) : any ->this : any +>(this) : typeof globalThis +>this : typeof globalThis >value : any (M) *= value; diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt index e3c9918aa4b..37e9ca6be1d 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.errors.txt @@ -2,7 +2,7 @@ tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignm tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(10,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(13,9): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(18,5): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(21,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(21,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(25,1): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(27,1): error TS2539: Cannot assign to 'C' because it is not a variable. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(30,1): error TS2539: Cannot assign to 'E' because it is not a variable. @@ -22,7 +22,7 @@ tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignm tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(65,21): error TS1128: Declaration or statement expected. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(66,11): error TS1005: ';' expected. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(69,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. -tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(72,1): error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(72,1): error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(73,2): error TS2539: Cannot assign to 'M' because it is not a variable. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(74,2): error TS2539: Cannot assign to 'C' because it is not a variable. tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignmentLHSIsValue.ts(75,2): error TS2539: Cannot assign to 'E' because it is not a variable. @@ -70,7 +70,7 @@ tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignm this **= value; ~~~~ -!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. // identifiers: module, class, enum, function module M { export var a; } @@ -161,7 +161,7 @@ tests/cases/conformance/es7/exponentiationOperator/compoundExponentiationAssignm // parentheses, the containted expression is value (this) **= value; ~~~~~~ -!!! error TS2364: The left-hand side of an assignment expression must be a variable or a property access. +!!! error TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type. (M) **= value; ~ !!! error TS2539: Cannot assign to 'M' because it is not a variable. diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.symbols b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.symbols index 7e85139b7a8..5596f648979 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.symbols +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.symbols @@ -36,6 +36,7 @@ function foo() { } this **= value; +>this : Symbol(globalThis) >value : Symbol(value, Decl(compoundExponentiationAssignmentLHSIsValue.ts, 1, 3)) // identifiers: module, class, enum, function @@ -135,6 +136,7 @@ foo() **= value; // parentheses, the containted expression is value (this) **= value; +>this : Symbol(globalThis) >value : Symbol(value, Decl(compoundExponentiationAssignmentLHSIsValue.ts, 1, 3)) (M) **= value; diff --git a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.types b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.types index 982b6b2bdee..58ec77add86 100644 --- a/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.types +++ b/tests/baselines/reference/compoundExponentiationAssignmentLHSIsValue.types @@ -42,7 +42,7 @@ function foo() { this **= value; >this **= value : number ->this : any +>this : typeof globalThis >value : any // identifiers: module, class, enum, function @@ -178,8 +178,8 @@ foo() **= value; // parentheses, the containted expression is value (this) **= value; >(this) **= value : number ->(this) : any ->this : any +>(this) : typeof globalThis +>this : typeof globalThis >value : any (M) **= value; diff --git a/tests/baselines/reference/computedPropertyNames20_ES5.symbols b/tests/baselines/reference/computedPropertyNames20_ES5.symbols index 2b249fd8f95..3ac422d6e73 100644 --- a/tests/baselines/reference/computedPropertyNames20_ES5.symbols +++ b/tests/baselines/reference/computedPropertyNames20_ES5.symbols @@ -4,4 +4,5 @@ var obj = { [this.bar]: 0 >[this.bar] : Symbol([this.bar], Decl(computedPropertyNames20_ES5.ts, 0, 11)) +>this : Symbol(globalThis) } diff --git a/tests/baselines/reference/computedPropertyNames20_ES5.types b/tests/baselines/reference/computedPropertyNames20_ES5.types index cc0614b3d0b..7a958724811 100644 --- a/tests/baselines/reference/computedPropertyNames20_ES5.types +++ b/tests/baselines/reference/computedPropertyNames20_ES5.types @@ -6,7 +6,7 @@ var obj = { [this.bar]: 0 >[this.bar] : number >this.bar : any ->this : any +>this : typeof globalThis >bar : any >0 : 0 } diff --git a/tests/baselines/reference/computedPropertyNames20_ES6.symbols b/tests/baselines/reference/computedPropertyNames20_ES6.symbols index ffd5645ccd6..62c934426fd 100644 --- a/tests/baselines/reference/computedPropertyNames20_ES6.symbols +++ b/tests/baselines/reference/computedPropertyNames20_ES6.symbols @@ -4,4 +4,5 @@ var obj = { [this.bar]: 0 >[this.bar] : Symbol([this.bar], Decl(computedPropertyNames20_ES6.ts, 0, 11)) +>this : Symbol(globalThis) } diff --git a/tests/baselines/reference/computedPropertyNames20_ES6.types b/tests/baselines/reference/computedPropertyNames20_ES6.types index 5ffc037860e..516559e3e3e 100644 --- a/tests/baselines/reference/computedPropertyNames20_ES6.types +++ b/tests/baselines/reference/computedPropertyNames20_ES6.types @@ -6,7 +6,7 @@ var obj = { [this.bar]: 0 >[this.bar] : number >this.bar : any ->this : any +>this : typeof globalThis >bar : any >0 : 0 } diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.symbols b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.symbols index c5f1afffb2f..f7e719e39d3 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.symbols +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.symbols @@ -579,6 +579,7 @@ module TypeScriptAllInOne { } public method2() { return 2 * this.method1(2); +>this : Symbol(globalThis) } } diff --git a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.types b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.types index c4428efcd4d..affae0f3108 100644 --- a/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.types +++ b/tests/baselines/reference/constructorWithIncompleteTypeAnnotation.types @@ -869,7 +869,7 @@ module TypeScriptAllInOne { >2 : 2 >this.method1(2) : any >this.method1 : any ->this : any +>this : typeof globalThis >method1 : any >2 : 2 } diff --git a/tests/baselines/reference/emitArrowFunctionThisCapturing.errors.txt b/tests/baselines/reference/emitArrowFunctionThisCapturing.errors.txt new file mode 100644 index 00000000000..2030b47b3ec --- /dev/null +++ b/tests/baselines/reference/emitArrowFunctionThisCapturing.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionThisCapturing.ts(6,10): error TS2540: Cannot assign to 'name' because it is a read-only property. + + +==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionThisCapturing.ts (1 errors) ==== + var f1 = () => { + this.age = 10 + }; + + var f2 = (x: string) => { + this.name = x + ~~~~ +!!! error TS2540: Cannot assign to 'name' because it is a read-only property. + } + + function foo(func: () => boolean) { } + foo(() => { + this.age = 100; + return true; + }); + \ No newline at end of file diff --git a/tests/baselines/reference/emitArrowFunctionThisCapturing.symbols b/tests/baselines/reference/emitArrowFunctionThisCapturing.symbols index ad62a0df5be..e130eafd770 100644 --- a/tests/baselines/reference/emitArrowFunctionThisCapturing.symbols +++ b/tests/baselines/reference/emitArrowFunctionThisCapturing.symbols @@ -3,6 +3,8 @@ var f1 = () => { >f1 : Symbol(f1, Decl(emitArrowFunctionThisCapturing.ts, 0, 3)) this.age = 10 +>this : Symbol(globalThis) + }; var f2 = (x: string) => { @@ -10,6 +12,9 @@ var f2 = (x: string) => { >x : Symbol(x, Decl(emitArrowFunctionThisCapturing.ts, 4, 10)) this.name = x +>this.name : Symbol(name, Decl(lib.dom.d.ts, --, --)) +>this : Symbol(globalThis) +>name : Symbol(name, Decl(lib.dom.d.ts, --, --)) >x : Symbol(x, Decl(emitArrowFunctionThisCapturing.ts, 4, 10)) } @@ -21,6 +26,8 @@ foo(() => { >foo : Symbol(foo, Decl(emitArrowFunctionThisCapturing.ts, 6, 1)) this.age = 100; +>this : Symbol(globalThis) + return true; }); diff --git a/tests/baselines/reference/emitArrowFunctionThisCapturing.types b/tests/baselines/reference/emitArrowFunctionThisCapturing.types index 0ef27791d17..8edaa3141da 100644 --- a/tests/baselines/reference/emitArrowFunctionThisCapturing.types +++ b/tests/baselines/reference/emitArrowFunctionThisCapturing.types @@ -6,7 +6,7 @@ var f1 = () => { this.age = 10 >this.age = 10 : 10 >this.age : any ->this : any +>this : typeof globalThis >age : any >10 : 10 @@ -20,7 +20,7 @@ var f2 = (x: string) => { this.name = x >this.name = x : string >this.name : any ->this : any +>this : typeof globalThis >name : any >x : string } @@ -37,7 +37,7 @@ foo(() => { this.age = 100; >this.age = 100 : 100 >this.age : any ->this : any +>this : typeof globalThis >age : any >100 : 100 diff --git a/tests/baselines/reference/emitArrowFunctionThisCapturingES6.errors.txt b/tests/baselines/reference/emitArrowFunctionThisCapturingES6.errors.txt new file mode 100644 index 00000000000..fb644a4127e --- /dev/null +++ b/tests/baselines/reference/emitArrowFunctionThisCapturingES6.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/es6/arrowFunction/emitArrowFunctionThisCapturingES6.ts(6,10): error TS2540: Cannot assign to 'name' because it is a read-only property. + + +==== tests/cases/conformance/es6/arrowFunction/emitArrowFunctionThisCapturingES6.ts (1 errors) ==== + var f1 = () => { + this.age = 10 + }; + + var f2 = (x: string) => { + this.name = x + ~~~~ +!!! error TS2540: Cannot assign to 'name' because it is a read-only property. + } + + function foo(func: () => boolean){ } + foo(() => { + this.age = 100; + return true; + }); + \ No newline at end of file diff --git a/tests/baselines/reference/emitArrowFunctionThisCapturingES6.symbols b/tests/baselines/reference/emitArrowFunctionThisCapturingES6.symbols index 0e8855dd680..d370a207de6 100644 --- a/tests/baselines/reference/emitArrowFunctionThisCapturingES6.symbols +++ b/tests/baselines/reference/emitArrowFunctionThisCapturingES6.symbols @@ -3,6 +3,8 @@ var f1 = () => { >f1 : Symbol(f1, Decl(emitArrowFunctionThisCapturingES6.ts, 0, 3)) this.age = 10 +>this : Symbol(globalThis) + }; var f2 = (x: string) => { @@ -10,6 +12,9 @@ var f2 = (x: string) => { >x : Symbol(x, Decl(emitArrowFunctionThisCapturingES6.ts, 4, 10)) this.name = x +>this.name : Symbol(name, Decl(lib.dom.d.ts, --, --)) +>this : Symbol(globalThis) +>name : Symbol(name, Decl(lib.dom.d.ts, --, --)) >x : Symbol(x, Decl(emitArrowFunctionThisCapturingES6.ts, 4, 10)) } @@ -21,6 +26,8 @@ foo(() => { >foo : Symbol(foo, Decl(emitArrowFunctionThisCapturingES6.ts, 6, 1)) this.age = 100; +>this : Symbol(globalThis) + return true; }); diff --git a/tests/baselines/reference/emitArrowFunctionThisCapturingES6.types b/tests/baselines/reference/emitArrowFunctionThisCapturingES6.types index 3c20bfd195c..c57317ec5bf 100644 --- a/tests/baselines/reference/emitArrowFunctionThisCapturingES6.types +++ b/tests/baselines/reference/emitArrowFunctionThisCapturingES6.types @@ -6,7 +6,7 @@ var f1 = () => { this.age = 10 >this.age = 10 : 10 >this.age : any ->this : any +>this : typeof globalThis >age : any >10 : 10 @@ -20,7 +20,7 @@ var f2 = (x: string) => { this.name = x >this.name = x : string >this.name : any ->this : any +>this : typeof globalThis >name : any >x : string } @@ -37,7 +37,7 @@ foo(() => { this.age = 100; >this.age = 100 : 100 >this.age : any ->this : any +>this : typeof globalThis >age : any >100 : 100 diff --git a/tests/baselines/reference/emitCapturingThisInTupleDestructuring1.symbols b/tests/baselines/reference/emitCapturingThisInTupleDestructuring1.symbols index 6bd13ccfd47..bfef6d5b3e3 100644 --- a/tests/baselines/reference/emitCapturingThisInTupleDestructuring1.symbols +++ b/tests/baselines/reference/emitCapturingThisInTupleDestructuring1.symbols @@ -8,6 +8,9 @@ wrapper((array: [any]) => { >array : Symbol(array, Decl(emitCapturingThisInTupleDestructuring1.ts, 1, 9)) [this.test, this.test1, this.test2] = array; // even though there is a compiler error, we should still emit lexical capture for "this" +>this : Symbol(globalThis) +>this : Symbol(globalThis) +>this : Symbol(globalThis) >array : Symbol(array, Decl(emitCapturingThisInTupleDestructuring1.ts, 1, 9)) }); diff --git a/tests/baselines/reference/emitCapturingThisInTupleDestructuring1.types b/tests/baselines/reference/emitCapturingThisInTupleDestructuring1.types index 7e9f03780ca..9cd06b6b560 100644 --- a/tests/baselines/reference/emitCapturingThisInTupleDestructuring1.types +++ b/tests/baselines/reference/emitCapturingThisInTupleDestructuring1.types @@ -13,13 +13,13 @@ wrapper((array: [any]) => { >[this.test, this.test1, this.test2] = array : [any] >[this.test, this.test1, this.test2] : [any, any, any] >this.test : any ->this : any +>this : typeof globalThis >test : any >this.test1 : any ->this : any +>this : typeof globalThis >test1 : any >this.test2 : any ->this : any +>this : typeof globalThis >test2 : any >array : [any] diff --git a/tests/baselines/reference/globalThisCapture.symbols b/tests/baselines/reference/globalThisCapture.symbols index bfb7bf147c0..9ece286c98f 100644 --- a/tests/baselines/reference/globalThisCapture.symbols +++ b/tests/baselines/reference/globalThisCapture.symbols @@ -1,6 +1,9 @@ === tests/cases/compiler/globalThisCapture.ts === // Add a lambda to ensure global 'this' capture is triggered (()=>this.window); +>this.window : Symbol(window, Decl(lib.dom.d.ts, --, --)) +>this : Symbol(globalThis) +>window : Symbol(window, Decl(lib.dom.d.ts, --, --)) var parts = []; >parts : Symbol(parts, Decl(globalThisCapture.ts, 3, 3)) diff --git a/tests/baselines/reference/globalThisCapture.types b/tests/baselines/reference/globalThisCapture.types index 063100ff78e..43a06138228 100644 --- a/tests/baselines/reference/globalThisCapture.types +++ b/tests/baselines/reference/globalThisCapture.types @@ -1,11 +1,11 @@ === tests/cases/compiler/globalThisCapture.ts === // Add a lambda to ensure global 'this' capture is triggered (()=>this.window); ->(()=>this.window) : () => any ->()=>this.window : () => any ->this.window : any ->this : any ->window : any +>(()=>this.window) : () => Window +>()=>this.window : () => Window +>this.window : Window +>this : typeof globalThis +>window : Window var parts = []; >parts : any[] diff --git a/tests/baselines/reference/globalThisPropertyAssignment.errors.txt b/tests/baselines/reference/globalThisPropertyAssignment.errors.txt new file mode 100644 index 00000000000..a02824415ae --- /dev/null +++ b/tests/baselines/reference/globalThisPropertyAssignment.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/es2019/globalThisPropertyAssignment.js(4,8): error TS2339: Property 'z' does not exist on type 'Window'. + + +==== tests/cases/conformance/es2019/globalThisPropertyAssignment.js (1 errors) ==== + this.x = 1 + var y = 2 + // should work in JS + window.z = 3 + ~ +!!! error TS2339: Property 'z' does not exist on type 'Window'. + // should work in JS (even though it's a secondary declaration) + globalThis.alpha = 4 + \ No newline at end of file diff --git a/tests/baselines/reference/globalThisPropertyAssignment.symbols b/tests/baselines/reference/globalThisPropertyAssignment.symbols new file mode 100644 index 00000000000..1ae4dd5af63 --- /dev/null +++ b/tests/baselines/reference/globalThisPropertyAssignment.symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/es2019/globalThisPropertyAssignment.js === +this.x = 1 +>this.x : Symbol(x, Decl(globalThisPropertyAssignment.js, 0, 0)) +>this : Symbol(globalThis) +>x : Symbol(x, Decl(globalThisPropertyAssignment.js, 0, 0)) + +var y = 2 +>y : Symbol(y, Decl(globalThisPropertyAssignment.js, 1, 3)) + +// should work in JS +window.z = 3 +>window : Symbol(window, Decl(lib.dom.d.ts, --, --), Decl(globalThisPropertyAssignment.js, 1, 9)) + +// should work in JS (even though it's a secondary declaration) +globalThis.alpha = 4 +>globalThis.alpha : Symbol(alpha, Decl(globalThisPropertyAssignment.js, 3, 12)) +>globalThis : Symbol(globalThis) +>alpha : Symbol(alpha, Decl(globalThisPropertyAssignment.js, 3, 12)) + diff --git a/tests/baselines/reference/globalThisPropertyAssignment.types b/tests/baselines/reference/globalThisPropertyAssignment.types new file mode 100644 index 00000000000..6be55e136b0 --- /dev/null +++ b/tests/baselines/reference/globalThisPropertyAssignment.types @@ -0,0 +1,28 @@ +=== tests/cases/conformance/es2019/globalThisPropertyAssignment.js === +this.x = 1 +>this.x = 1 : 1 +>this.x : number +>this : typeof globalThis +>x : number +>1 : 1 + +var y = 2 +>y : number +>2 : 2 + +// should work in JS +window.z = 3 +>window.z = 3 : 3 +>window.z : any +>window : Window +>z : any +>3 : 3 + +// should work in JS (even though it's a secondary declaration) +globalThis.alpha = 4 +>globalThis.alpha = 4 : 4 +>globalThis.alpha : number +>globalThis : typeof globalThis +>alpha : number +>4 : 4 + diff --git a/tests/baselines/reference/globalThisReadonlyProperties.errors.txt b/tests/baselines/reference/globalThisReadonlyProperties.errors.txt new file mode 100644 index 00000000000..925cf90a10c --- /dev/null +++ b/tests/baselines/reference/globalThisReadonlyProperties.errors.txt @@ -0,0 +1,15 @@ +tests/cases/conformance/es2019/globalThisReadonlyProperties.ts(1,12): error TS2540: Cannot assign to 'globalThis' because it is a read-only property. +tests/cases/conformance/es2019/globalThisReadonlyProperties.ts(5,12): error TS2540: Cannot assign to 'y' because it is a read-only property. + + +==== tests/cases/conformance/es2019/globalThisReadonlyProperties.ts (2 errors) ==== + globalThis.globalThis = 1 as any // should error + ~~~~~~~~~~ +!!! error TS2540: Cannot assign to 'globalThis' because it is a read-only property. + var x = 1 + const y = 2 + globalThis.x = 3 + globalThis.y = 4 // should error + ~ +!!! error TS2540: Cannot assign to 'y' because it is a read-only property. + \ No newline at end of file diff --git a/tests/baselines/reference/globalThisReadonlyProperties.js b/tests/baselines/reference/globalThisReadonlyProperties.js new file mode 100644 index 00000000000..3012608a125 --- /dev/null +++ b/tests/baselines/reference/globalThisReadonlyProperties.js @@ -0,0 +1,14 @@ +//// [globalThisReadonlyProperties.ts] +globalThis.globalThis = 1 as any // should error +var x = 1 +const y = 2 +globalThis.x = 3 +globalThis.y = 4 // should error + + +//// [globalThisReadonlyProperties.js] +globalThis.globalThis = 1; // should error +var x = 1; +var y = 2; +globalThis.x = 3; +globalThis.y = 4; // should error diff --git a/tests/baselines/reference/globalThisReadonlyProperties.symbols b/tests/baselines/reference/globalThisReadonlyProperties.symbols new file mode 100644 index 00000000000..df59ee45ca3 --- /dev/null +++ b/tests/baselines/reference/globalThisReadonlyProperties.symbols @@ -0,0 +1,22 @@ +=== tests/cases/conformance/es2019/globalThisReadonlyProperties.ts === +globalThis.globalThis = 1 as any // should error +>globalThis.globalThis : Symbol(globalThis) +>globalThis : Symbol(globalThis) +>globalThis : Symbol(globalThis) + +var x = 1 +>x : Symbol(x, Decl(globalThisReadonlyProperties.ts, 1, 3)) + +const y = 2 +>y : Symbol(y, Decl(globalThisReadonlyProperties.ts, 2, 5)) + +globalThis.x = 3 +>globalThis.x : Symbol(x, Decl(globalThisReadonlyProperties.ts, 1, 3)) +>globalThis : Symbol(globalThis) +>x : Symbol(x, Decl(globalThisReadonlyProperties.ts, 1, 3)) + +globalThis.y = 4 // should error +>globalThis.y : Symbol(y, Decl(globalThisReadonlyProperties.ts, 2, 5)) +>globalThis : Symbol(globalThis) +>y : Symbol(y, Decl(globalThisReadonlyProperties.ts, 2, 5)) + diff --git a/tests/baselines/reference/globalThisReadonlyProperties.types b/tests/baselines/reference/globalThisReadonlyProperties.types new file mode 100644 index 00000000000..05b3d7c84e8 --- /dev/null +++ b/tests/baselines/reference/globalThisReadonlyProperties.types @@ -0,0 +1,31 @@ +=== tests/cases/conformance/es2019/globalThisReadonlyProperties.ts === +globalThis.globalThis = 1 as any // should error +>globalThis.globalThis = 1 as any : any +>globalThis.globalThis : any +>globalThis : typeof globalThis +>globalThis : any +>1 as any : any +>1 : 1 + +var x = 1 +>x : number +>1 : 1 + +const y = 2 +>y : 2 +>2 : 2 + +globalThis.x = 3 +>globalThis.x = 3 : 3 +>globalThis.x : number +>globalThis : typeof globalThis +>x : number +>3 : 3 + +globalThis.y = 4 // should error +>globalThis.y = 4 : 4 +>globalThis.y : any +>globalThis : typeof globalThis +>y : any +>4 : 4 + diff --git a/tests/baselines/reference/globalThisTypeIndexAccess.js b/tests/baselines/reference/globalThisTypeIndexAccess.js new file mode 100644 index 00000000000..aef5c97ed9a --- /dev/null +++ b/tests/baselines/reference/globalThisTypeIndexAccess.js @@ -0,0 +1,5 @@ +//// [globalThisTypeIndexAccess.ts] +declare const w_e: (typeof globalThis)["globalThis"] + + +//// [globalThisTypeIndexAccess.js] diff --git a/tests/baselines/reference/globalThisTypeIndexAccess.symbols b/tests/baselines/reference/globalThisTypeIndexAccess.symbols new file mode 100644 index 00000000000..460867fb1f1 --- /dev/null +++ b/tests/baselines/reference/globalThisTypeIndexAccess.symbols @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es2019/globalThisTypeIndexAccess.ts === +declare const w_e: (typeof globalThis)["globalThis"] +>w_e : Symbol(w_e, Decl(globalThisTypeIndexAccess.ts, 0, 13)) +>globalThis : Symbol(globalThis) + diff --git a/tests/baselines/reference/globalThisTypeIndexAccess.types b/tests/baselines/reference/globalThisTypeIndexAccess.types new file mode 100644 index 00000000000..c290b744071 --- /dev/null +++ b/tests/baselines/reference/globalThisTypeIndexAccess.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es2019/globalThisTypeIndexAccess.ts === +declare const w_e: (typeof globalThis)["globalThis"] +>w_e : typeof globalThis +>globalThis : typeof globalThis + diff --git a/tests/baselines/reference/globalThisUnknown.errors.txt b/tests/baselines/reference/globalThisUnknown.errors.txt new file mode 100644 index 00000000000..fc9a8485b64 --- /dev/null +++ b/tests/baselines/reference/globalThisUnknown.errors.txt @@ -0,0 +1,20 @@ +tests/cases/conformance/es2019/globalThisUnknown.ts(4,5): error TS2339: Property 'hi' does not exist on type 'Window & typeof globalThis'. + + +==== tests/cases/conformance/es2019/globalThisUnknown.ts (1 errors) ==== + declare let win: Window & typeof globalThis; + + // this access should be an error + win.hi + ~~ +!!! error TS2339: Property 'hi' does not exist on type 'Window & typeof globalThis'. + // these two should be fine, with type any + this.hi + globalThis.hi + + // element access is always ok without noImplicitAny + win['hi'] + this['hi'] + globalThis['hi'] + + \ No newline at end of file diff --git a/tests/baselines/reference/globalThisUnknown.js b/tests/baselines/reference/globalThisUnknown.js new file mode 100644 index 00000000000..9763100c129 --- /dev/null +++ b/tests/baselines/reference/globalThisUnknown.js @@ -0,0 +1,26 @@ +//// [globalThisUnknown.ts] +declare let win: Window & typeof globalThis; + +// this access should be an error +win.hi +// these two should be fine, with type any +this.hi +globalThis.hi + +// element access is always ok without noImplicitAny +win['hi'] +this['hi'] +globalThis['hi'] + + + +//// [globalThisUnknown.js] +// this access should be an error +win.hi; +// these two should be fine, with type any +this.hi; +globalThis.hi; +// element access is always ok without noImplicitAny +win['hi']; +this['hi']; +globalThis['hi']; diff --git a/tests/baselines/reference/globalThisUnknown.symbols b/tests/baselines/reference/globalThisUnknown.symbols new file mode 100644 index 00000000000..4f8437bf244 --- /dev/null +++ b/tests/baselines/reference/globalThisUnknown.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/es2019/globalThisUnknown.ts === +declare let win: Window & typeof globalThis; +>win : Symbol(win, Decl(globalThisUnknown.ts, 0, 11)) +>Window : Symbol(Window, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>globalThis : Symbol(globalThis) + +// this access should be an error +win.hi +>win : Symbol(win, Decl(globalThisUnknown.ts, 0, 11)) + +// these two should be fine, with type any +this.hi +>this : Symbol(globalThis) + +globalThis.hi +>globalThis : Symbol(globalThis) + +// element access is always ok without noImplicitAny +win['hi'] +>win : Symbol(win, Decl(globalThisUnknown.ts, 0, 11)) + +this['hi'] +>this : Symbol(globalThis) + +globalThis['hi'] +>globalThis : Symbol(globalThis) + + diff --git a/tests/baselines/reference/globalThisUnknown.types b/tests/baselines/reference/globalThisUnknown.types new file mode 100644 index 00000000000..42ac606ec54 --- /dev/null +++ b/tests/baselines/reference/globalThisUnknown.types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2019/globalThisUnknown.ts === +declare let win: Window & typeof globalThis; +>win : Window & typeof globalThis +>globalThis : typeof globalThis + +// this access should be an error +win.hi +>win.hi : any +>win : Window & typeof globalThis +>hi : any + +// these two should be fine, with type any +this.hi +>this.hi : any +>this : typeof globalThis +>hi : any + +globalThis.hi +>globalThis.hi : any +>globalThis : typeof globalThis +>hi : any + +// element access is always ok without noImplicitAny +win['hi'] +>win['hi'] : any +>win : Window & typeof globalThis +>'hi' : "hi" + +this['hi'] +>this['hi'] : any +>this : typeof globalThis +>'hi' : "hi" + +globalThis['hi'] +>globalThis['hi'] : any +>globalThis : typeof globalThis +>'hi' : "hi" + + diff --git a/tests/baselines/reference/globalThisUnknownNoImplicitAny.errors.txt b/tests/baselines/reference/globalThisUnknownNoImplicitAny.errors.txt new file mode 100644 index 00000000000..fc5e91de594 --- /dev/null +++ b/tests/baselines/reference/globalThisUnknownNoImplicitAny.errors.txt @@ -0,0 +1,32 @@ +tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts(4,5): error TS2339: Property 'hi' does not exist on type 'Window & typeof globalThis'. +tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts(5,6): error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. +tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts(6,12): error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. +tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts(8,1): error TS7017: Element implicitly has an 'any' type because type 'Window & typeof globalThis' has no index signature. +tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts(9,1): error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. +tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts(10,1): error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. + + +==== tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts (6 errors) ==== + declare let win: Window & typeof globalThis; + + // all accesses should be errors + win.hi + ~~ +!!! error TS2339: Property 'hi' does not exist on type 'Window & typeof globalThis'. + this.hi + ~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. + globalThis.hi + ~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. + + win['hi'] + ~~~~~~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'Window & typeof globalThis' has no index signature. + this['hi'] + ~~~~~~~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. + globalThis['hi'] + ~~~~~~~~~~~~~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. + \ No newline at end of file diff --git a/tests/baselines/reference/globalThisUnknownNoImplicitAny.js b/tests/baselines/reference/globalThisUnknownNoImplicitAny.js new file mode 100644 index 00000000000..cc1952e0afc --- /dev/null +++ b/tests/baselines/reference/globalThisUnknownNoImplicitAny.js @@ -0,0 +1,21 @@ +//// [globalThisUnknownNoImplicitAny.ts] +declare let win: Window & typeof globalThis; + +// all accesses should be errors +win.hi +this.hi +globalThis.hi + +win['hi'] +this['hi'] +globalThis['hi'] + + +//// [globalThisUnknownNoImplicitAny.js] +// all accesses should be errors +win.hi; +this.hi; +globalThis.hi; +win['hi']; +this['hi']; +globalThis['hi']; diff --git a/tests/baselines/reference/globalThisUnknownNoImplicitAny.symbols b/tests/baselines/reference/globalThisUnknownNoImplicitAny.symbols new file mode 100644 index 00000000000..6aee6d6051c --- /dev/null +++ b/tests/baselines/reference/globalThisUnknownNoImplicitAny.symbols @@ -0,0 +1,25 @@ +=== tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts === +declare let win: Window & typeof globalThis; +>win : Symbol(win, Decl(globalThisUnknownNoImplicitAny.ts, 0, 11)) +>Window : Symbol(Window, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) +>globalThis : Symbol(globalThis) + +// all accesses should be errors +win.hi +>win : Symbol(win, Decl(globalThisUnknownNoImplicitAny.ts, 0, 11)) + +this.hi +>this : Symbol(globalThis) + +globalThis.hi +>globalThis : Symbol(globalThis) + +win['hi'] +>win : Symbol(win, Decl(globalThisUnknownNoImplicitAny.ts, 0, 11)) + +this['hi'] +>this : Symbol(globalThis) + +globalThis['hi'] +>globalThis : Symbol(globalThis) + diff --git a/tests/baselines/reference/globalThisUnknownNoImplicitAny.types b/tests/baselines/reference/globalThisUnknownNoImplicitAny.types new file mode 100644 index 00000000000..19611a785b4 --- /dev/null +++ b/tests/baselines/reference/globalThisUnknownNoImplicitAny.types @@ -0,0 +1,36 @@ +=== tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts === +declare let win: Window & typeof globalThis; +>win : Window & typeof globalThis +>globalThis : typeof globalThis + +// all accesses should be errors +win.hi +>win.hi : any +>win : Window & typeof globalThis +>hi : any + +this.hi +>this.hi : any +>this : typeof globalThis +>hi : any + +globalThis.hi +>globalThis.hi : any +>globalThis : typeof globalThis +>hi : any + +win['hi'] +>win['hi'] : any +>win : Window & typeof globalThis +>'hi' : "hi" + +this['hi'] +>this['hi'] : any +>this : typeof globalThis +>'hi' : "hi" + +globalThis['hi'] +>globalThis['hi'] : any +>globalThis : typeof globalThis +>'hi' : "hi" + diff --git a/tests/baselines/reference/globalThisVarDeclaration.errors.txt b/tests/baselines/reference/globalThisVarDeclaration.errors.txt new file mode 100644 index 00000000000..daf2349c6b0 --- /dev/null +++ b/tests/baselines/reference/globalThisVarDeclaration.errors.txt @@ -0,0 +1,69 @@ +tests/cases/conformance/es2019/actual.ts(8,6): error TS2339: Property 'a' does not exist on type 'Window'. +tests/cases/conformance/es2019/actual.ts(9,6): error TS2339: Property 'b' does not exist on type 'Window'. +tests/cases/conformance/es2019/actual.ts(10,8): error TS2339: Property 'a' does not exist on type 'Window'. +tests/cases/conformance/es2019/actual.ts(11,8): error TS2339: Property 'b' does not exist on type 'Window'. +tests/cases/conformance/es2019/actual.ts(12,5): error TS2339: Property 'a' does not exist on type 'Window'. +tests/cases/conformance/es2019/actual.ts(13,5): error TS2339: Property 'b' does not exist on type 'Window'. +tests/cases/conformance/es2019/b.js(8,6): error TS2339: Property 'a' does not exist on type 'Window'. +tests/cases/conformance/es2019/b.js(9,6): error TS2339: Property 'b' does not exist on type 'Window'. +tests/cases/conformance/es2019/b.js(10,8): error TS2339: Property 'a' does not exist on type 'Window'. +tests/cases/conformance/es2019/b.js(11,8): error TS2339: Property 'b' does not exist on type 'Window'. +tests/cases/conformance/es2019/b.js(12,5): error TS2339: Property 'a' does not exist on type 'Window'. +tests/cases/conformance/es2019/b.js(13,5): error TS2339: Property 'b' does not exist on type 'Window'. + + +==== tests/cases/conformance/es2019/b.js (6 errors) ==== + var a = 10; + this.a; + this.b; + globalThis.a; + globalThis.b; + + // DOM access is not supported until the index signature is handled more strictly + self.a; + ~ +!!! error TS2339: Property 'a' does not exist on type 'Window'. + self.b; + ~ +!!! error TS2339: Property 'b' does not exist on type 'Window'. + window.a; + ~ +!!! error TS2339: Property 'a' does not exist on type 'Window'. + window.b; + ~ +!!! error TS2339: Property 'b' does not exist on type 'Window'. + top.a; + ~ +!!! error TS2339: Property 'a' does not exist on type 'Window'. + top.b; + ~ +!!! error TS2339: Property 'b' does not exist on type 'Window'. + +==== tests/cases/conformance/es2019/actual.ts (6 errors) ==== + var b = 10; + this.a; + this.b; + globalThis.a; + globalThis.b; + + // same here -- no DOM access to globalThis yet + self.a; + ~ +!!! error TS2339: Property 'a' does not exist on type 'Window'. + self.b; + ~ +!!! error TS2339: Property 'b' does not exist on type 'Window'. + window.a; + ~ +!!! error TS2339: Property 'a' does not exist on type 'Window'. + window.b; + ~ +!!! error TS2339: Property 'b' does not exist on type 'Window'. + top.a; + ~ +!!! error TS2339: Property 'a' does not exist on type 'Window'. + top.b; + ~ +!!! error TS2339: Property 'b' does not exist on type 'Window'. + + \ No newline at end of file diff --git a/tests/baselines/reference/globalThisVarDeclaration.js b/tests/baselines/reference/globalThisVarDeclaration.js new file mode 100644 index 00000000000..2ae75af703e --- /dev/null +++ b/tests/baselines/reference/globalThisVarDeclaration.js @@ -0,0 +1,59 @@ +//// [tests/cases/conformance/es2019/globalThisVarDeclaration.ts] //// + +//// [b.js] +var a = 10; +this.a; +this.b; +globalThis.a; +globalThis.b; + +// DOM access is not supported until the index signature is handled more strictly +self.a; +self.b; +window.a; +window.b; +top.a; +top.b; + +//// [actual.ts] +var b = 10; +this.a; +this.b; +globalThis.a; +globalThis.b; + +// same here -- no DOM access to globalThis yet +self.a; +self.b; +window.a; +window.b; +top.a; +top.b; + + + +//// [output.js] +var a = 10; +this.a; +this.b; +globalThis.a; +globalThis.b; +// DOM access is not supported until the index signature is handled more strictly +self.a; +self.b; +window.a; +window.b; +top.a; +top.b; +var b = 10; +this.a; +this.b; +globalThis.a; +globalThis.b; +// same here -- no DOM access to globalThis yet +self.a; +self.b; +window.a; +window.b; +top.a; +top.b; diff --git a/tests/baselines/reference/globalThisVarDeclaration.symbols b/tests/baselines/reference/globalThisVarDeclaration.symbols new file mode 100644 index 00000000000..b2d7feb37fd --- /dev/null +++ b/tests/baselines/reference/globalThisVarDeclaration.symbols @@ -0,0 +1,87 @@ +=== tests/cases/conformance/es2019/b.js === +var a = 10; +>a : Symbol(a, Decl(b.js, 0, 3)) + +this.a; +>this.a : Symbol(a, Decl(b.js, 0, 3)) +>this : Symbol(globalThis) +>a : Symbol(a, Decl(b.js, 0, 3)) + +this.b; +>this.b : Symbol(b, Decl(actual.ts, 0, 3)) +>this : Symbol(globalThis) +>b : Symbol(b, Decl(actual.ts, 0, 3)) + +globalThis.a; +>globalThis.a : Symbol(a, Decl(b.js, 0, 3)) +>globalThis : Symbol(globalThis) +>a : Symbol(a, Decl(b.js, 0, 3)) + +globalThis.b; +>globalThis.b : Symbol(b, Decl(actual.ts, 0, 3)) +>globalThis : Symbol(globalThis) +>b : Symbol(b, Decl(actual.ts, 0, 3)) + +// DOM access is not supported until the index signature is handled more strictly +self.a; +>self : Symbol(self, Decl(lib.dom.d.ts, --, --)) + +self.b; +>self : Symbol(self, Decl(lib.dom.d.ts, --, --)) + +window.a; +>window : Symbol(window, Decl(lib.dom.d.ts, --, --)) + +window.b; +>window : Symbol(window, Decl(lib.dom.d.ts, --, --)) + +top.a; +>top : Symbol(top, Decl(lib.dom.d.ts, --, --)) + +top.b; +>top : Symbol(top, Decl(lib.dom.d.ts, --, --)) + +=== tests/cases/conformance/es2019/actual.ts === +var b = 10; +>b : Symbol(b, Decl(actual.ts, 0, 3)) + +this.a; +>this.a : Symbol(a, Decl(b.js, 0, 3)) +>this : Symbol(globalThis) +>a : Symbol(a, Decl(b.js, 0, 3)) + +this.b; +>this.b : Symbol(b, Decl(actual.ts, 0, 3)) +>this : Symbol(globalThis) +>b : Symbol(b, Decl(actual.ts, 0, 3)) + +globalThis.a; +>globalThis.a : Symbol(a, Decl(b.js, 0, 3)) +>globalThis : Symbol(globalThis) +>a : Symbol(a, Decl(b.js, 0, 3)) + +globalThis.b; +>globalThis.b : Symbol(b, Decl(actual.ts, 0, 3)) +>globalThis : Symbol(globalThis) +>b : Symbol(b, Decl(actual.ts, 0, 3)) + +// same here -- no DOM access to globalThis yet +self.a; +>self : Symbol(self, Decl(lib.dom.d.ts, --, --)) + +self.b; +>self : Symbol(self, Decl(lib.dom.d.ts, --, --)) + +window.a; +>window : Symbol(window, Decl(lib.dom.d.ts, --, --)) + +window.b; +>window : Symbol(window, Decl(lib.dom.d.ts, --, --)) + +top.a; +>top : Symbol(top, Decl(lib.dom.d.ts, --, --)) + +top.b; +>top : Symbol(top, Decl(lib.dom.d.ts, --, --)) + + diff --git a/tests/baselines/reference/globalThisVarDeclaration.types b/tests/baselines/reference/globalThisVarDeclaration.types new file mode 100644 index 00000000000..9c520f667dc --- /dev/null +++ b/tests/baselines/reference/globalThisVarDeclaration.types @@ -0,0 +1,113 @@ +=== tests/cases/conformance/es2019/b.js === +var a = 10; +>a : number +>10 : 10 + +this.a; +>this.a : number +>this : typeof globalThis +>a : number + +this.b; +>this.b : number +>this : typeof globalThis +>b : number + +globalThis.a; +>globalThis.a : number +>globalThis : typeof globalThis +>a : number + +globalThis.b; +>globalThis.b : number +>globalThis : typeof globalThis +>b : number + +// DOM access is not supported until the index signature is handled more strictly +self.a; +>self.a : any +>self : Window +>a : any + +self.b; +>self.b : any +>self : Window +>b : any + +window.a; +>window.a : any +>window : Window +>a : any + +window.b; +>window.b : any +>window : Window +>b : any + +top.a; +>top.a : any +>top : Window +>a : any + +top.b; +>top.b : any +>top : Window +>b : any + +=== tests/cases/conformance/es2019/actual.ts === +var b = 10; +>b : number +>10 : 10 + +this.a; +>this.a : number +>this : typeof globalThis +>a : number + +this.b; +>this.b : number +>this : typeof globalThis +>b : number + +globalThis.a; +>globalThis.a : number +>globalThis : typeof globalThis +>a : number + +globalThis.b; +>globalThis.b : number +>globalThis : typeof globalThis +>b : number + +// same here -- no DOM access to globalThis yet +self.a; +>self.a : any +>self : Window +>a : any + +self.b; +>self.b : any +>self : Window +>b : any + +window.a; +>window.a : any +>window : Window +>a : any + +window.b; +>window.b : any +>window : Window +>b : any + +top.a; +>top.a : any +>top : Window +>a : any + +top.b; +>top.b : any +>top : Window +>b : any + + diff --git a/tests/baselines/reference/implicitAnyInCatch.symbols b/tests/baselines/reference/implicitAnyInCatch.symbols index 7ce3ac40f36..4f09ecdcbe5 100644 --- a/tests/baselines/reference/implicitAnyInCatch.symbols +++ b/tests/baselines/reference/implicitAnyInCatch.symbols @@ -8,6 +8,7 @@ try { } catch (error) { } for (var key in this) { } >key : Symbol(key, Decl(implicitAnyInCatch.ts, 4, 8)) +>this : Symbol(globalThis) class C { >C : Symbol(C, Decl(implicitAnyInCatch.ts, 4, 25)) diff --git a/tests/baselines/reference/implicitAnyInCatch.types b/tests/baselines/reference/implicitAnyInCatch.types index 6f70165407f..5619ec53622 100644 --- a/tests/baselines/reference/implicitAnyInCatch.types +++ b/tests/baselines/reference/implicitAnyInCatch.types @@ -13,7 +13,7 @@ try { } catch (error) { } for (var key in this) { } >key : string ->this : any +>this : typeof globalThis class C { >C : C diff --git a/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.symbols b/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.symbols index 25af733e40f..c53ac6b1948 100644 --- a/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.symbols +++ b/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.symbols @@ -127,6 +127,7 @@ export const MySFC = (props: {x: number, y: number, children?: predom.JSX.Elemen >props.y : Symbol(y, Decl(component.tsx, 3, 40)) >props : Symbol(props, Decl(component.tsx, 3, 22)) >y : Symbol(y, Decl(component.tsx, 3, 40)) +>this : Symbol(globalThis) >p : Symbol(predom.JSX.IntrinsicElements, Decl(renderer2.d.ts, 1, 19)) export class MyClass implements predom.JSX.Element { diff --git a/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.types b/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.types index a1c0e79909d..ab33876cbda 100644 --- a/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.types +++ b/tests/baselines/reference/inlineJsxFactoryDeclarationsLocalTypes.types @@ -99,7 +99,7 @@ export const MySFC = (props: {x: number, y: number, children?: predom.JSX.Elemen >y : number >this.props.children : any >this.props : any ->this : any +>this : typeof globalThis >props : any >children : any >p : any diff --git a/tests/baselines/reference/jsxAttributeWithoutExpressionReact.symbols b/tests/baselines/reference/jsxAttributeWithoutExpressionReact.symbols index fc489ff899d..a12ac0b1c92 100644 --- a/tests/baselines/reference/jsxAttributeWithoutExpressionReact.symbols +++ b/tests/baselines/reference/jsxAttributeWithoutExpressionReact.symbols @@ -12,6 +12,7 @@ declare var React: any; } dataSource={this.state.ds} renderRow={}> >dataSource : Symbol(dataSource, Decl(jsxAttributeWithoutExpressionReact.tsx, 4, 5)) +>this : Symbol(globalThis) >renderRow : Symbol(renderRow, Decl(jsxAttributeWithoutExpressionReact.tsx, 4, 32)) diff --git a/tests/baselines/reference/jsxAttributeWithoutExpressionReact.types b/tests/baselines/reference/jsxAttributeWithoutExpressionReact.types index e5c192b4876..dac0e2c3df4 100644 --- a/tests/baselines/reference/jsxAttributeWithoutExpressionReact.types +++ b/tests/baselines/reference/jsxAttributeWithoutExpressionReact.types @@ -21,7 +21,7 @@ declare var React: any; >dataSource : any >this.state.ds : any >this.state : any ->this : any +>this : typeof globalThis >state : any >ds : any >renderRow : any diff --git a/tests/baselines/reference/jsxReactTestSuite.symbols b/tests/baselines/reference/jsxReactTestSuite.symbols index dfcc4c70bd8..8d656a8ecb1 100644 --- a/tests/baselines/reference/jsxReactTestSuite.symbols +++ b/tests/baselines/reference/jsxReactTestSuite.symbols @@ -39,6 +39,8 @@ declare var hasOwnProperty:any;
{this.props.children} +>this : Symbol(globalThis) +
;
@@ -57,6 +59,8 @@ declare var hasOwnProperty:any; >Composite : Symbol(Composite, Decl(jsxReactTestSuite.tsx, 2, 11)) {this.props.children} +>this : Symbol(globalThis) + ; >Composite : Symbol(Composite, Decl(jsxReactTestSuite.tsx, 2, 11)) @@ -154,6 +158,7 @@ var x = >Component : Symbol(Component, Decl(jsxReactTestSuite.tsx, 1, 11)) {...this.props} sound="moo" />; +>this : Symbol(globalThis) >sound : Symbol(sound, Decl(jsxReactTestSuite.tsx, 93, 19)) ; diff --git a/tests/baselines/reference/jsxReactTestSuite.types b/tests/baselines/reference/jsxReactTestSuite.types index 3637a21c268..dae8b8ae912 100644 --- a/tests/baselines/reference/jsxReactTestSuite.types +++ b/tests/baselines/reference/jsxReactTestSuite.types @@ -47,7 +47,7 @@ declare var hasOwnProperty:any; {this.props.children} >this.props.children : any >this.props : any ->this : any +>this : typeof globalThis >props : any >children : any @@ -89,7 +89,7 @@ declare var hasOwnProperty:any; {this.props.children} >this.props.children : any >this.props : any ->this : any +>this : typeof globalThis >props : any >children : any @@ -262,7 +262,7 @@ var x = {...this.props} sound="moo" />; >this.props : any ->this : any +>this : typeof globalThis >props : any >sound : string diff --git a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.symbols b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.symbols index 306e629e82d..e906195f9b1 100644 --- a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.symbols +++ b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.symbols @@ -1,9 +1,12 @@ === tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts === return this.edit(role) +>this : Symbol(globalThis) + .then((role: Role) => >role : Symbol(role, Decl(multiLinePropertyAccessAndArrowFunctionIndent1.ts, 1, 11)) this.roleService.add(role) +>this : Symbol(globalThis) >role : Symbol(role, Decl(multiLinePropertyAccessAndArrowFunctionIndent1.ts, 1, 11)) .then((data: ng.IHttpPromiseCallbackArg) => data.data)); diff --git a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.types b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.types index 5347dbb876d..9f35e8fff57 100644 --- a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.types +++ b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.types @@ -4,7 +4,7 @@ return this.edit(role) >this.edit(role) .then : any >this.edit(role) : any >this.edit : any ->this : any +>this : typeof globalThis >edit : any >role : any @@ -19,7 +19,7 @@ return this.edit(role) >this.roleService.add(role) : any >this.roleService.add : any >this.roleService : any ->this : any +>this : typeof globalThis >roleService : any >add : any >role : any diff --git a/tests/baselines/reference/noImplicitThisFunctions.errors.txt b/tests/baselines/reference/noImplicitThisFunctions.errors.txt index aac8faa566c..8fb99eb2724 100644 --- a/tests/baselines/reference/noImplicitThisFunctions.errors.txt +++ b/tests/baselines/reference/noImplicitThisFunctions.errors.txt @@ -1,6 +1,6 @@ tests/cases/compiler/noImplicitThisFunctions.ts(13,12): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. -tests/cases/compiler/noImplicitThisFunctions.ts(17,38): error TS7041: The containing arrow function captures the global value of 'this' which implicitly has type 'any'. -tests/cases/compiler/noImplicitThisFunctions.ts(18,22): error TS7041: The containing arrow function captures the global value of 'this' which implicitly has type 'any'. +tests/cases/compiler/noImplicitThisFunctions.ts(17,38): error TS7041: The containing arrow function captures the global value of 'this'. +tests/cases/compiler/noImplicitThisFunctions.ts(18,22): error TS7041: The containing arrow function captures the global value of 'this'. tests/cases/compiler/noImplicitThisFunctions.ts(20,36): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. tests/cases/compiler/noImplicitThisFunctions.ts(21,50): error TS2683: 'this' implicitly has type 'any' because it does not have a type annotation. @@ -26,10 +26,10 @@ tests/cases/compiler/noImplicitThisFunctions.ts(21,50): error TS2683: 'this' imp // error: `this` is `window`, but is still of type `any` let f4: (b: number) => number = b => this.c + b; ~~~~ -!!! error TS7041: The containing arrow function captures the global value of 'this' which implicitly has type 'any'. +!!! error TS7041: The containing arrow function captures the global value of 'this'. let f5 = () => () => this; ~~~~ -!!! error TS7041: The containing arrow function captures the global value of 'this' which implicitly has type 'any'. +!!! error TS7041: The containing arrow function captures the global value of 'this'. let f6 = function() { return () => this; }; ~~~~ diff --git a/tests/baselines/reference/noImplicitThisFunctions.symbols b/tests/baselines/reference/noImplicitThisFunctions.symbols index d8d937893f3..a86b117f910 100644 --- a/tests/baselines/reference/noImplicitThisFunctions.symbols +++ b/tests/baselines/reference/noImplicitThisFunctions.symbols @@ -31,10 +31,12 @@ let f4: (b: number) => number = b => this.c + b; >f4 : Symbol(f4, Decl(noImplicitThisFunctions.ts, 16, 3)) >b : Symbol(b, Decl(noImplicitThisFunctions.ts, 16, 9)) >b : Symbol(b, Decl(noImplicitThisFunctions.ts, 16, 31)) +>this : Symbol(globalThis) >b : Symbol(b, Decl(noImplicitThisFunctions.ts, 16, 31)) let f5 = () => () => this; >f5 : Symbol(f5, Decl(noImplicitThisFunctions.ts, 17, 3)) +>this : Symbol(globalThis) let f6 = function() { return () => this; }; >f6 : Symbol(f6, Decl(noImplicitThisFunctions.ts, 19, 3)) diff --git a/tests/baselines/reference/noImplicitThisFunctions.types b/tests/baselines/reference/noImplicitThisFunctions.types index f5b93fa9efb..639e84f650b 100644 --- a/tests/baselines/reference/noImplicitThisFunctions.types +++ b/tests/baselines/reference/noImplicitThisFunctions.types @@ -42,15 +42,15 @@ let f4: (b: number) => number = b => this.c + b; >b : number >this.c + b : any >this.c : any ->this : any +>this : typeof globalThis >c : any >b : number let f5 = () => () => this; ->f5 : () => () => any ->() => () => this : () => () => any ->() => this : () => any ->this : any +>f5 : () => () => typeof globalThis +>() => () => this : () => () => typeof globalThis +>() => this : () => typeof globalThis +>this : typeof globalThis let f6 = function() { return () => this; }; >f6 : () => () => any diff --git a/tests/baselines/reference/parserCommaInTypeMemberList2.symbols b/tests/baselines/reference/parserCommaInTypeMemberList2.symbols index ffaac46fd27..9bc7a392292 100644 --- a/tests/baselines/reference/parserCommaInTypeMemberList2.symbols +++ b/tests/baselines/reference/parserCommaInTypeMemberList2.symbols @@ -5,4 +5,5 @@ var s = $.extend< { workItem: any }, { workItem: any, width: string }>({ workIte >workItem : Symbol(workItem, Decl(parserCommaInTypeMemberList2.ts, 0, 38)) >width : Symbol(width, Decl(parserCommaInTypeMemberList2.ts, 0, 53)) >workItem : Symbol(workItem, Decl(parserCommaInTypeMemberList2.ts, 0, 72)) +>this : Symbol(globalThis) diff --git a/tests/baselines/reference/parserCommaInTypeMemberList2.types b/tests/baselines/reference/parserCommaInTypeMemberList2.types index cfa270d9838..0b172848ccd 100644 --- a/tests/baselines/reference/parserCommaInTypeMemberList2.types +++ b/tests/baselines/reference/parserCommaInTypeMemberList2.types @@ -11,7 +11,7 @@ var s = $.extend< { workItem: any }, { workItem: any, width: string }>({ workIte >{ workItem: this._workItem } : { workItem: any; } >workItem : any >this._workItem : any ->this : any +>this : typeof globalThis >_workItem : any >{} : {} diff --git a/tests/baselines/reference/parserConditionalExpression1.symbols b/tests/baselines/reference/parserConditionalExpression1.symbols index e271c68b4a0..91453101af1 100644 --- a/tests/baselines/reference/parserConditionalExpression1.symbols +++ b/tests/baselines/reference/parserConditionalExpression1.symbols @@ -1,3 +1,6 @@ === tests/cases/conformance/parser/ecmascript5/Expressions/parserConditionalExpression1.ts === (a=this.R[c])?a.JW||(a.e5(this,c),a.JW=_.l):this.A -No type information for this code. \ No newline at end of file +>this : Symbol(globalThis) +>this : Symbol(globalThis) +>this : Symbol(globalThis) + diff --git a/tests/baselines/reference/parserConditionalExpression1.types b/tests/baselines/reference/parserConditionalExpression1.types index 930d744d48a..d0fb5556033 100644 --- a/tests/baselines/reference/parserConditionalExpression1.types +++ b/tests/baselines/reference/parserConditionalExpression1.types @@ -6,7 +6,7 @@ >a : any >this.R[c] : any >this.R : any ->this : any +>this : typeof globalThis >R : any >c : any >a.JW||(a.e5(this,c),a.JW=_.l) : any @@ -19,7 +19,7 @@ >a.e5 : any >a : any >e5 : any ->this : any +>this : typeof globalThis >c : any >a.JW=_.l : any >a.JW : any @@ -29,6 +29,6 @@ >_ : any >l : any >this.A : any ->this : any +>this : typeof globalThis >A : any diff --git a/tests/baselines/reference/parserForStatement8.errors.txt b/tests/baselines/reference/parserForStatement8.errors.txt index 21ea55e3b09..ac04ed5e548 100644 --- a/tests/baselines/reference/parserForStatement8.errors.txt +++ b/tests/baselines/reference/parserForStatement8.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement8.ts(1,6): error TS2406: The left-hand side of a 'for...in' statement must be a variable or a property access. +tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement8.ts(1,6): error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement8.ts(1,14): error TS2304: Cannot find name 'b'. ==== tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement8.ts (2 errors) ==== for (this in b) { ~~~~ -!!! error TS2406: The left-hand side of a 'for...in' statement must be a variable or a property access. +!!! error TS2405: The left-hand side of a 'for...in' statement must be of type 'string' or 'any'. ~ !!! error TS2304: Cannot find name 'b'. } \ No newline at end of file diff --git a/tests/baselines/reference/parserForStatement8.symbols b/tests/baselines/reference/parserForStatement8.symbols index 4e34f8b90c9..2133f54f57c 100644 --- a/tests/baselines/reference/parserForStatement8.symbols +++ b/tests/baselines/reference/parserForStatement8.symbols @@ -1,4 +1,4 @@ === tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement8.ts === for (this in b) { -No type information for this code.} -No type information for this code. \ No newline at end of file +>this : Symbol(globalThis) +} diff --git a/tests/baselines/reference/parserForStatement8.types b/tests/baselines/reference/parserForStatement8.types index 0a520528759..72572e68cfc 100644 --- a/tests/baselines/reference/parserForStatement8.types +++ b/tests/baselines/reference/parserForStatement8.types @@ -1,5 +1,5 @@ === tests/cases/conformance/parser/ecmascript5/Statements/parserForStatement8.ts === for (this in b) { ->this : any +>this : typeof globalThis >b : any } diff --git a/tests/baselines/reference/parserModifierOnStatementInBlock2.symbols b/tests/baselines/reference/parserModifierOnStatementInBlock2.symbols index c118eff4a86..daf115443ae 100644 --- a/tests/baselines/reference/parserModifierOnStatementInBlock2.symbols +++ b/tests/baselines/reference/parserModifierOnStatementInBlock2.symbols @@ -2,5 +2,6 @@ { declare var x = this; >x : Symbol(x, Decl(parserModifierOnStatementInBlock2.ts, 1, 14)) +>this : Symbol(globalThis) } diff --git a/tests/baselines/reference/parserModifierOnStatementInBlock2.types b/tests/baselines/reference/parserModifierOnStatementInBlock2.types index a74d3a0c544..3bb3aee1cf9 100644 --- a/tests/baselines/reference/parserModifierOnStatementInBlock2.types +++ b/tests/baselines/reference/parserModifierOnStatementInBlock2.types @@ -1,7 +1,7 @@ === tests/cases/conformance/parser/ecmascript5/ErrorRecovery/parserModifierOnStatementInBlock2.ts === { declare var x = this; ->x : any ->this : any +>x : typeof globalThis +>this : typeof globalThis } diff --git a/tests/baselines/reference/parserStrictMode16.symbols b/tests/baselines/reference/parserStrictMode16.symbols index 655201fbea2..bef54a8af99 100644 --- a/tests/baselines/reference/parserStrictMode16.symbols +++ b/tests/baselines/reference/parserStrictMode16.symbols @@ -1,7 +1,8 @@ === tests/cases/conformance/parser/ecmascript5/StrictMode/parserStrictMode16.ts === "use strict"; -No type information for this code.delete this; -No type information for this code.delete 1; -No type information for this code.delete null; -No type information for this code.delete "a"; -No type information for this code. \ No newline at end of file +delete this; +>this : Symbol(globalThis) + +delete 1; +delete null; +delete "a"; diff --git a/tests/baselines/reference/parserStrictMode16.types b/tests/baselines/reference/parserStrictMode16.types index fbe701f374b..94c8a6a6bd7 100644 --- a/tests/baselines/reference/parserStrictMode16.types +++ b/tests/baselines/reference/parserStrictMode16.types @@ -4,7 +4,7 @@ delete this; >delete this : boolean ->this : any +>this : typeof globalThis delete 1; >delete 1 : boolean diff --git a/tests/baselines/reference/parserUnaryExpression1.errors.txt b/tests/baselines/reference/parserUnaryExpression1.errors.txt index 278960d53f3..40019965512 100644 --- a/tests/baselines/reference/parserUnaryExpression1.errors.txt +++ b/tests/baselines/reference/parserUnaryExpression1.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression1.ts(1,3): error TS2357: The operand of an increment or decrement operator must be a variable or a property access. +tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression1.ts(1,3): error TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type. ==== tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression1.ts (1 errors) ==== ++this; ~~~~ -!!! error TS2357: The operand of an increment or decrement operator must be a variable or a property access. \ No newline at end of file +!!! error TS2356: An arithmetic operand must be of type 'any', 'number', 'bigint' or an enum type. \ No newline at end of file diff --git a/tests/baselines/reference/parserUnaryExpression1.symbols b/tests/baselines/reference/parserUnaryExpression1.symbols index 2311212b63d..053c922f947 100644 --- a/tests/baselines/reference/parserUnaryExpression1.symbols +++ b/tests/baselines/reference/parserUnaryExpression1.symbols @@ -1,3 +1,4 @@ === tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression1.ts === ++this; -No type information for this code. \ No newline at end of file +>this : Symbol(globalThis) + diff --git a/tests/baselines/reference/parserUnaryExpression1.types b/tests/baselines/reference/parserUnaryExpression1.types index 5803ac1f1f8..534dad66474 100644 --- a/tests/baselines/reference/parserUnaryExpression1.types +++ b/tests/baselines/reference/parserUnaryExpression1.types @@ -1,5 +1,5 @@ === tests/cases/conformance/parser/ecmascript5/Expressions/parserUnaryExpression1.ts === ++this; >++this : number ->this : any +>this : typeof globalThis diff --git a/tests/baselines/reference/propertyWrappedInTry.symbols b/tests/baselines/reference/propertyWrappedInTry.symbols index cce74c0981b..4d570fee1bb 100644 --- a/tests/baselines/reference/propertyWrappedInTry.symbols +++ b/tests/baselines/reference/propertyWrappedInTry.symbols @@ -14,6 +14,7 @@ class Foo { public baz() { return this.bar; // doesn't get rewritten to Foo.bar. +>this : Symbol(globalThis) } diff --git a/tests/baselines/reference/propertyWrappedInTry.types b/tests/baselines/reference/propertyWrappedInTry.types index 29be27edee9..8138f41091f 100644 --- a/tests/baselines/reference/propertyWrappedInTry.types +++ b/tests/baselines/reference/propertyWrappedInTry.types @@ -21,7 +21,7 @@ class Foo { return this.bar; // doesn't get rewritten to Foo.bar. >this.bar : any ->this : any +>this : typeof globalThis >bar : any } diff --git a/tests/baselines/reference/thisInInvalidContexts.errors.txt b/tests/baselines/reference/thisInInvalidContexts.errors.txt index 3581d6d6f29..7a357e1327e 100644 --- a/tests/baselines/reference/thisInInvalidContexts.errors.txt +++ b/tests/baselines/reference/thisInInvalidContexts.errors.txt @@ -3,11 +3,12 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(14,15): tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(22,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(38,25): error TS2507: Type 'typeof globalThis' is not a constructor function type. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(44,9): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): error TS2332: 'this' cannot be referenced in current location. -==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts (7 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts (8 errors) ==== //'this' in static member initializer class ErrClass1 { static t = this; // Error @@ -56,6 +57,8 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContexts.ts(45,9): !!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. class ErrClass3 extends this { + ~~~~ +!!! error TS2507: Type 'typeof globalThis' is not a constructor function type. } diff --git a/tests/baselines/reference/thisInInvalidContexts.symbols b/tests/baselines/reference/thisInInvalidContexts.symbols index 417b9cc5ea8..7fecdf73f43 100644 --- a/tests/baselines/reference/thisInInvalidContexts.symbols +++ b/tests/baselines/reference/thisInInvalidContexts.symbols @@ -69,6 +69,7 @@ genericFunc(undefined); // Should be an error class ErrClass3 extends this { >ErrClass3 : Symbol(ErrClass3, Decl(thisInInvalidContexts.ts, 35, 29)) +>this : Symbol(globalThis) } diff --git a/tests/baselines/reference/thisInInvalidContexts.types b/tests/baselines/reference/thisInInvalidContexts.types index 672a8fe58c4..6f35006b6c1 100644 --- a/tests/baselines/reference/thisInInvalidContexts.types +++ b/tests/baselines/reference/thisInInvalidContexts.types @@ -72,7 +72,7 @@ genericFunc(undefined); // Should be an error class ErrClass3 extends this { >ErrClass3 : ErrClass3 ->this : any +>this : typeof globalThis } diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt index f89b2897892..4cfd109b00e 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.errors.txt @@ -3,11 +3,12 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(22,15): error TS17009: 'super' must be called before accessing 'this' in the constructor of a derived class. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(28,13): error TS2331: 'this' cannot be referenced in a module or namespace body. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(36,13): error TS2526: A 'this' type is available only in a non-static member of a class or interface. +tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(38,25): error TS2507: Type 'typeof globalThis' is not a constructor function type. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(44,9): error TS2332: 'this' cannot be referenced in current location. tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts(45,9): error TS2332: 'this' cannot be referenced in current location. -==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (7 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalModule.ts (8 errors) ==== //'this' in static member initializer class ErrClass1 { static t = this; // Error @@ -56,6 +57,8 @@ tests/cases/conformance/expressions/thisKeyword/thisInInvalidContextsExternalMod !!! error TS2526: A 'this' type is available only in a non-static member of a class or interface. class ErrClass3 extends this { + ~~~~ +!!! error TS2507: Type 'typeof globalThis' is not a constructor function type. } diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.symbols b/tests/baselines/reference/thisInInvalidContextsExternalModule.symbols index 9cf261fa672..ad52fbdabeb 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.symbols +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.symbols @@ -69,6 +69,7 @@ genericFunc(undefined); // Should be an error class ErrClass3 extends this { >ErrClass3 : Symbol(ErrClass3, Decl(thisInInvalidContextsExternalModule.ts, 35, 29)) +>this : Symbol(globalThis) } diff --git a/tests/baselines/reference/thisInInvalidContextsExternalModule.types b/tests/baselines/reference/thisInInvalidContextsExternalModule.types index cdc13173077..e6ad34c9a20 100644 --- a/tests/baselines/reference/thisInInvalidContextsExternalModule.types +++ b/tests/baselines/reference/thisInInvalidContextsExternalModule.types @@ -72,7 +72,7 @@ genericFunc(undefined); // Should be an error class ErrClass3 extends this { >ErrClass3 : ErrClass3 ->this : any +>this : typeof globalThis } diff --git a/tests/baselines/reference/thisTypeInFunctions.symbols b/tests/baselines/reference/thisTypeInFunctions.symbols index ad16785f288..c1dcdb9829d 100644 --- a/tests/baselines/reference/thisTypeInFunctions.symbols +++ b/tests/baselines/reference/thisTypeInFunctions.symbols @@ -126,6 +126,7 @@ let impl: I = { explicitVoid2: () => this.a, // ok, this: any because it refers to some outer object (window?) >explicitVoid2 : Symbol(explicitVoid2, Decl(thisTypeInFunctions.ts, 38, 10)) +>this : Symbol(globalThis) explicitVoid1() { return 12; }, >explicitVoid1 : Symbol(explicitVoid1, Decl(thisTypeInFunctions.ts, 39, 32)) @@ -365,6 +366,7 @@ let unboundToSpecified: (this: { y: number }, x: number) => number = x => x + th >x : Symbol(x, Decl(thisTypeInFunctions.ts, 92, 45)) >x : Symbol(x, Decl(thisTypeInFunctions.ts, 92, 68)) >x : Symbol(x, Decl(thisTypeInFunctions.ts, 92, 68)) +>this : Symbol(globalThis) let specifiedToSpecified: (this: {y: number}, x: number) => number = explicitStructural; >specifiedToSpecified : Symbol(specifiedToSpecified, Decl(thisTypeInFunctions.ts, 93, 3)) @@ -495,6 +497,9 @@ c.explicitC = m => m + this.n; >explicitC : Symbol(C.explicitC, Decl(thisTypeInFunctions.ts, 8, 5)) >m : Symbol(m, Decl(thisTypeInFunctions.ts, 117, 13)) >m : Symbol(m, Decl(thisTypeInFunctions.ts, 117, 13)) +>this.n : Symbol(n, Decl(thisTypeInFunctions.ts, 190, 3)) +>this : Symbol(globalThis) +>n : Symbol(n, Decl(thisTypeInFunctions.ts, 190, 3)) c.explicitThis = m => m + this.n; >c.explicitThis : Symbol(C.explicitThis, Decl(thisTypeInFunctions.ts, 5, 14)) @@ -502,6 +507,9 @@ c.explicitThis = m => m + this.n; >explicitThis : Symbol(C.explicitThis, Decl(thisTypeInFunctions.ts, 5, 14)) >m : Symbol(m, Decl(thisTypeInFunctions.ts, 118, 16)) >m : Symbol(m, Decl(thisTypeInFunctions.ts, 118, 16)) +>this.n : Symbol(n, Decl(thisTypeInFunctions.ts, 190, 3)) +>this : Symbol(globalThis) +>n : Symbol(n, Decl(thisTypeInFunctions.ts, 190, 3)) c.explicitProperty = m => m + this.n; >c.explicitProperty : Symbol(C.explicitProperty, Decl(thisTypeInFunctions.ts, 11, 5)) @@ -509,6 +517,9 @@ c.explicitProperty = m => m + this.n; >explicitProperty : Symbol(C.explicitProperty, Decl(thisTypeInFunctions.ts, 11, 5)) >m : Symbol(m, Decl(thisTypeInFunctions.ts, 119, 20)) >m : Symbol(m, Decl(thisTypeInFunctions.ts, 119, 20)) +>this.n : Symbol(n, Decl(thisTypeInFunctions.ts, 190, 3)) +>this : Symbol(globalThis) +>n : Symbol(n, Decl(thisTypeInFunctions.ts, 190, 3)) //NOTE: this=C here, I guess? c.explicitThis = explicitCFunction; diff --git a/tests/baselines/reference/thisTypeInFunctions.types b/tests/baselines/reference/thisTypeInFunctions.types index caf4e9a5971..7408a764f1a 100644 --- a/tests/baselines/reference/thisTypeInFunctions.types +++ b/tests/baselines/reference/thisTypeInFunctions.types @@ -137,7 +137,7 @@ let impl: I = { >explicitVoid2 : () => any >() => this.a : () => any >this.a : any ->this : any +>this : typeof globalThis >a : any explicitVoid1() { return 12; }, @@ -431,7 +431,7 @@ let unboundToSpecified: (this: { y: number }, x: number) => number = x => x + th >x + this.y : any >x : number >this.y : any ->this : any +>this : typeof globalThis >y : any let specifiedToSpecified: (this: {y: number}, x: number) => number = explicitStructural; @@ -580,43 +580,43 @@ c.explicitProperty = m => m; // this inside lambdas refer to outer scope // the outer-scoped lambda at top-level is still just `any` c.explicitC = m => m + this.n; ->c.explicitC = m => m + this.n : (this: C, m: number) => any +>c.explicitC = m => m + this.n : (this: C, m: number) => number >c.explicitC : (this: C, m: number) => number >c : C >explicitC : (this: C, m: number) => number ->m => m + this.n : (this: C, m: number) => any +>m => m + this.n : (this: C, m: number) => number >m : number ->m + this.n : any +>m + this.n : number >m : number ->this.n : any ->this : any ->n : any +>this.n : number +>this : typeof globalThis +>n : number c.explicitThis = m => m + this.n; ->c.explicitThis = m => m + this.n : (this: C, m: number) => any +>c.explicitThis = m => m + this.n : (this: C, m: number) => number >c.explicitThis : (this: C, m: number) => number >c : C >explicitThis : (this: C, m: number) => number ->m => m + this.n : (this: C, m: number) => any +>m => m + this.n : (this: C, m: number) => number >m : number ->m + this.n : any +>m + this.n : number >m : number ->this.n : any ->this : any ->n : any +>this.n : number +>this : typeof globalThis +>n : number c.explicitProperty = m => m + this.n; ->c.explicitProperty = m => m + this.n : (this: { n: number; }, m: number) => any +>c.explicitProperty = m => m + this.n : (this: { n: number; }, m: number) => number >c.explicitProperty : (this: { n: number; }, m: number) => number >c : C >explicitProperty : (this: { n: number; }, m: number) => number ->m => m + this.n : (this: { n: number; }, m: number) => any +>m => m + this.n : (this: { n: number; }, m: number) => number >m : number ->m + this.n : any +>m + this.n : number >m : number ->this.n : any ->this : any ->n : any +>this.n : number +>this : typeof globalThis +>n : number //NOTE: this=C here, I guess? c.explicitThis = explicitCFunction; diff --git a/tests/baselines/reference/thisTypeInFunctionsNegative.symbols b/tests/baselines/reference/thisTypeInFunctionsNegative.symbols index 024ae663a9d..14566bbf946 100644 --- a/tests/baselines/reference/thisTypeInFunctionsNegative.symbols +++ b/tests/baselines/reference/thisTypeInFunctionsNegative.symbols @@ -134,6 +134,7 @@ let impl: I = { }, explicitVoid2: () => this.a, // ok, `this:any` because it refers to an outer object >explicitVoid2 : Symbol(explicitVoid2, Decl(thisTypeInFunctionsNegative.ts, 39, 6)) +>this : Symbol(globalThis) explicitStructural: () => 12, >explicitStructural : Symbol(explicitStructural, Decl(thisTypeInFunctionsNegative.ts, 40, 32)) @@ -655,6 +656,7 @@ function initializer(this: C = new C()): number { return this.n; } >C : Symbol(C, Decl(thisTypeInFunctionsNegative.ts, 0, 0)) > : Symbol((Missing), Decl(thisTypeInFunctionsNegative.ts, 171, 30)) >C : Symbol(C, Decl(thisTypeInFunctionsNegative.ts, 171, 34)) +>this : Symbol(globalThis) // can't name parameters 'this' in a lambda. c.explicitProperty = (this, m) => m + this.n; @@ -664,6 +666,7 @@ c.explicitProperty = (this, m) => m + this.n; >this : Symbol(this, Decl(thisTypeInFunctionsNegative.ts, 174, 22)) >m : Symbol(m, Decl(thisTypeInFunctionsNegative.ts, 174, 27)) >m : Symbol(m, Decl(thisTypeInFunctionsNegative.ts, 174, 27)) +>this : Symbol(globalThis) const f2 = (this: {n: number}, m: number) => m + this.n; >f2 : Symbol(f2, Decl(thisTypeInFunctionsNegative.ts, 175, 5)) @@ -672,6 +675,7 @@ const f2 = (this: {n: number}, m: number) => m + this.n; >n : Symbol(n, Decl(thisTypeInFunctionsNegative.ts, 175, 22)) >m : Symbol(m, Decl(thisTypeInFunctionsNegative.ts, 175, 33)) >m : Symbol(m, Decl(thisTypeInFunctionsNegative.ts, 175, 33)) +>this : Symbol(globalThis) const f3 = async (this: {n: number}, m: number) => m + this.n; >f3 : Symbol(f3, Decl(thisTypeInFunctionsNegative.ts, 176, 5)) @@ -679,6 +683,7 @@ const f3 = async (this: {n: number}, m: number) => m + this.n; >n : Symbol(n, Decl(thisTypeInFunctionsNegative.ts, 176, 25)) >m : Symbol(m, Decl(thisTypeInFunctionsNegative.ts, 176, 36)) >m : Symbol(m, Decl(thisTypeInFunctionsNegative.ts, 176, 36)) +>this : Symbol(globalThis) const f4 = async (this: {n: number}, m: number) => m + this.n; >f4 : Symbol(f4, Decl(thisTypeInFunctionsNegative.ts, 177, 5)) @@ -687,4 +692,5 @@ const f4 = async (this: {n: number}, m: number) => m + this.n; >n : Symbol(n, Decl(thisTypeInFunctionsNegative.ts, 177, 28)) >m : Symbol(m, Decl(thisTypeInFunctionsNegative.ts, 177, 39)) >m : Symbol(m, Decl(thisTypeInFunctionsNegative.ts, 177, 39)) +>this : Symbol(globalThis) diff --git a/tests/baselines/reference/thisTypeInFunctionsNegative.types b/tests/baselines/reference/thisTypeInFunctionsNegative.types index 90a5f06ad40..3a86203772f 100644 --- a/tests/baselines/reference/thisTypeInFunctionsNegative.types +++ b/tests/baselines/reference/thisTypeInFunctionsNegative.types @@ -143,7 +143,7 @@ let impl: I = { >explicitVoid2 : () => any >() => this.a : () => any >this.a : any ->this : any +>this : typeof globalThis >a : any explicitStructural: () => 12, @@ -751,7 +751,7 @@ function initializer(this: C = new C()): number { return this.n; } > : any >number : any >this.n : any ->this : any +>this : typeof globalThis >n : any // can't name parameters 'this' in a lambda. @@ -766,7 +766,7 @@ c.explicitProperty = (this, m) => m + this.n; >m + this.n : any >m : number >this.n : any ->this : any +>this : typeof globalThis >n : any const f2 = (this: {n: number}, m: number) => m + this.n; @@ -778,7 +778,7 @@ const f2 = (this: {n: number}, m: number) => m + this.n; >m + this.n : any >m : number >this.n : any ->this : any +>this : typeof globalThis >n : any const f3 = async (this: {n: number}, m: number) => m + this.n; @@ -790,7 +790,7 @@ const f3 = async (this: {n: number}, m: number) => m + this.n; >m + this.n : any >m : number >this.n : any ->this : any +>this : typeof globalThis >n : any const f4 = async (this: {n: number}, m: number) => m + this.n; @@ -802,6 +802,6 @@ const f4 = async (this: {n: number}, m: number) => m + this.n; >m + this.n : any >m : number >this.n : any ->this : any +>this : typeof globalThis >n : any diff --git a/tests/baselines/reference/topLevelLambda2.symbols b/tests/baselines/reference/topLevelLambda2.symbols index 712d0a1611a..412a7c8a547 100644 --- a/tests/baselines/reference/topLevelLambda2.symbols +++ b/tests/baselines/reference/topLevelLambda2.symbols @@ -5,4 +5,7 @@ function foo(x:any) {} foo(()=>this.window); >foo : Symbol(foo, Decl(topLevelLambda2.ts, 0, 0)) +>this.window : Symbol(window, Decl(lib.dom.d.ts, --, --)) +>this : Symbol(globalThis) +>window : Symbol(window, Decl(lib.dom.d.ts, --, --)) diff --git a/tests/baselines/reference/topLevelLambda2.types b/tests/baselines/reference/topLevelLambda2.types index 7dcb909cdf9..ddca05514d0 100644 --- a/tests/baselines/reference/topLevelLambda2.types +++ b/tests/baselines/reference/topLevelLambda2.types @@ -6,8 +6,8 @@ function foo(x:any) {} foo(()=>this.window); >foo(()=>this.window) : void >foo : (x: any) => void ->()=>this.window : () => any ->this.window : any ->this : any ->window : any +>()=>this.window : () => Window +>this.window : Window +>this : typeof globalThis +>window : Window diff --git a/tests/baselines/reference/topLevelLambda3.symbols b/tests/baselines/reference/topLevelLambda3.symbols index 6ec9476ff74..7dd41958b7f 100644 --- a/tests/baselines/reference/topLevelLambda3.symbols +++ b/tests/baselines/reference/topLevelLambda3.symbols @@ -1,4 +1,7 @@ === tests/cases/compiler/topLevelLambda3.ts === var f = () => {this.window;} >f : Symbol(f, Decl(topLevelLambda3.ts, 0, 3)) +>this.window : Symbol(window, Decl(lib.dom.d.ts, --, --)) +>this : Symbol(globalThis) +>window : Symbol(window, Decl(lib.dom.d.ts, --, --)) diff --git a/tests/baselines/reference/topLevelLambda3.types b/tests/baselines/reference/topLevelLambda3.types index e96d40880fc..b2bb8f30bad 100644 --- a/tests/baselines/reference/topLevelLambda3.types +++ b/tests/baselines/reference/topLevelLambda3.types @@ -2,7 +2,7 @@ var f = () => {this.window;} >f : () => void >() => {this.window;} : () => void ->this.window : any ->this : any ->window : any +>this.window : Window +>this : typeof globalThis +>window : Window diff --git a/tests/baselines/reference/topLevelLambda4.symbols b/tests/baselines/reference/topLevelLambda4.symbols index a4f403a762f..202d1bf90d5 100644 --- a/tests/baselines/reference/topLevelLambda4.symbols +++ b/tests/baselines/reference/topLevelLambda4.symbols @@ -1,4 +1,7 @@ === tests/cases/compiler/topLevelLambda4.ts === export var x = () => this.window; >x : Symbol(x, Decl(topLevelLambda4.ts, 0, 10)) +>this.window : Symbol(window, Decl(lib.dom.d.ts, --, --)) +>this : Symbol(globalThis) +>window : Symbol(window, Decl(lib.dom.d.ts, --, --)) diff --git a/tests/baselines/reference/topLevelLambda4.types b/tests/baselines/reference/topLevelLambda4.types index f6c8752c267..081f5c47c5a 100644 --- a/tests/baselines/reference/topLevelLambda4.types +++ b/tests/baselines/reference/topLevelLambda4.types @@ -1,8 +1,8 @@ === tests/cases/compiler/topLevelLambda4.ts === export var x = () => this.window; ->x : () => any ->() => this.window : () => any ->this.window : any ->this : any ->window : any +>x : () => Window +>() => this.window : () => Window +>this.window : Window +>this : typeof globalThis +>window : Window diff --git a/tests/baselines/reference/topLevelThisAssignment.symbols b/tests/baselines/reference/topLevelThisAssignment.symbols index e9b94983bf2..4ac7e799848 100644 --- a/tests/baselines/reference/topLevelThisAssignment.symbols +++ b/tests/baselines/reference/topLevelThisAssignment.symbols @@ -1,10 +1,23 @@ === tests/cases/conformance/salsa/a.js === this.a = 10; -No type information for this code.this.a; -No type information for this code.a; -No type information for this code. -No type information for this code.=== tests/cases/conformance/salsa/b.js === +>this.a : Symbol(a, Decl(a.js, 0, 0)) +>this : Symbol(globalThis) +>a : Symbol(a, Decl(a.js, 0, 0)) + this.a; -No type information for this code.a; -No type information for this code. -No type information for this code. \ No newline at end of file +>this.a : Symbol(a, Decl(a.js, 0, 0)) +>this : Symbol(globalThis) +>a : Symbol(a, Decl(a.js, 0, 0)) + +a; +>a : Symbol(a, Decl(a.js, 0, 0)) + +=== tests/cases/conformance/salsa/b.js === +this.a; +>this.a : Symbol(a, Decl(a.js, 0, 0)) +>this : Symbol(globalThis) +>a : Symbol(a, Decl(a.js, 0, 0)) + +a; +>a : Symbol(a, Decl(a.js, 0, 0)) + diff --git a/tests/baselines/reference/topLevelThisAssignment.types b/tests/baselines/reference/topLevelThisAssignment.types index 92bb458b41f..11c7b5a82e1 100644 --- a/tests/baselines/reference/topLevelThisAssignment.types +++ b/tests/baselines/reference/topLevelThisAssignment.types @@ -1,25 +1,25 @@ === tests/cases/conformance/salsa/a.js === this.a = 10; >this.a = 10 : 10 ->this.a : any ->this : any ->a : any +>this.a : number +>this : typeof globalThis +>a : number >10 : 10 this.a; ->this.a : any ->this : any ->a : any +>this.a : number +>this : typeof globalThis +>a : number a; ->a : error +>a : number === tests/cases/conformance/salsa/b.js === this.a; ->this.a : any ->this : any ->a : any +>this.a : number +>this : typeof globalThis +>a : number a; ->a : error +>a : number diff --git a/tests/baselines/reference/tsxAttributeResolution15.errors.txt b/tests/baselines/reference/tsxAttributeResolution15.errors.txt index f4c9c14deb5..ca86178b578 100644 --- a/tests/baselines/reference/tsxAttributeResolution15.errors.txt +++ b/tests/baselines/reference/tsxAttributeResolution15.errors.txt @@ -1,8 +1,9 @@ tests/cases/conformance/jsx/file.tsx(11,10): error TS2322: Type '{ prop1: string; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes & { children?: ReactNode; }'. Property 'prop1' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes & { children?: ReactNode; }'. +tests/cases/conformance/jsx/file.tsx(14,44): error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. -==== tests/cases/conformance/jsx/file.tsx (1 errors) ==== +==== tests/cases/conformance/jsx/file.tsx (2 errors) ==== import React = require('react'); class BigGreeter extends React.Component<{ }, {}> { @@ -20,4 +21,6 @@ tests/cases/conformance/jsx/file.tsx(11,10): error TS2322: Type '{ prop1: string // OK let b = { this.textInput = input; }} /> + ~~~~~~~~~ +!!! error TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature. let c = \ No newline at end of file diff --git a/tests/baselines/reference/tsxAttributeResolution15.symbols b/tests/baselines/reference/tsxAttributeResolution15.symbols index 5c91d12a103..c366c93cef1 100644 --- a/tests/baselines/reference/tsxAttributeResolution15.symbols +++ b/tests/baselines/reference/tsxAttributeResolution15.symbols @@ -31,6 +31,7 @@ let b = { this.textInput = input; }} /> >BigGreeter : Symbol(BigGreeter, Decl(file.tsx, 0, 32)) >ref : Symbol(ref, Decl(file.tsx, 13, 19)) >input : Symbol(input, Decl(file.tsx, 13, 26)) +>this : Symbol(globalThis) >input : Symbol(input, Decl(file.tsx, 13, 26)) let c = diff --git a/tests/baselines/reference/tsxAttributeResolution15.types b/tests/baselines/reference/tsxAttributeResolution15.types index b95dcffcaf7..469f146cc45 100644 --- a/tests/baselines/reference/tsxAttributeResolution15.types +++ b/tests/baselines/reference/tsxAttributeResolution15.types @@ -37,7 +37,7 @@ let b = { this.textInput = input; }} /> >input : BigGreeter >this.textInput = input : BigGreeter >this.textInput : any ->this : any +>this : typeof globalThis >textInput : any >input : BigGreeter diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution4.symbols b/tests/baselines/reference/tsxSpreadAttributesResolution4.symbols index e599665b156..cb357c8a20d 100644 --- a/tests/baselines/reference/tsxSpreadAttributesResolution4.symbols +++ b/tests/baselines/reference/tsxSpreadAttributesResolution4.symbols @@ -79,6 +79,7 @@ let e3 = { this.textInput = input; } }} /> >EmptyProp : Symbol(EmptyProp, Decl(file.tsx, 19, 30)) >ref : Symbol(ref, Decl(file.tsx, 31, 25)) >input : Symbol(input, Decl(file.tsx, 31, 32)) +>this : Symbol(globalThis) >input : Symbol(input, Decl(file.tsx, 31, 32)) let e4 = diff --git a/tests/baselines/reference/tsxSpreadAttributesResolution4.types b/tests/baselines/reference/tsxSpreadAttributesResolution4.types index 194993348dc..82173c0df83 100644 --- a/tests/baselines/reference/tsxSpreadAttributesResolution4.types +++ b/tests/baselines/reference/tsxSpreadAttributesResolution4.types @@ -89,7 +89,7 @@ let e3 = { this.textInput = input; } }} /> >input : EmptyProp >this.textInput = input : EmptyProp >this.textInput : any ->this : any +>this : typeof globalThis >textInput : any >input : EmptyProp diff --git a/tests/baselines/reference/typeFromPropertyAssignment23.symbols b/tests/baselines/reference/typeFromPropertyAssignment23.symbols index 2ba8651ea53..f28bf54ac7a 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment23.symbols +++ b/tests/baselines/reference/typeFromPropertyAssignment23.symbols @@ -38,6 +38,8 @@ D.prototype.foo = () => { >foo : Symbol(D.foo, Decl(a.js, 14, 21)) this.n = 'not checked, so no error' +>this : Symbol(globalThis) +>n : Symbol(n, Decl(a.js, 15, 26)) } // post-class prototype assignments are trying to show that these properties are abstract diff --git a/tests/baselines/reference/typeFromPropertyAssignment23.types b/tests/baselines/reference/typeFromPropertyAssignment23.types index 4e540e3962f..03bf1d91776 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment23.types +++ b/tests/baselines/reference/typeFromPropertyAssignment23.types @@ -46,7 +46,7 @@ D.prototype.foo = () => { this.n = 'not checked, so no error' >this.n = 'not checked, so no error' : "not checked, so no error" >this.n : any ->this : any +>this : typeof globalThis >n : any >'not checked, so no error' : "not checked, so no error" } diff --git a/tests/baselines/reference/typeFromPropertyAssignment9.symbols b/tests/baselines/reference/typeFromPropertyAssignment9.symbols index 27188c71b32..2ebec8f5204 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment9.symbols +++ b/tests/baselines/reference/typeFromPropertyAssignment9.symbols @@ -118,6 +118,11 @@ min.nest = this.min.nest || function () { }; >min.nest : Symbol(min.nest, Decl(a.js, 29, 27), Decl(a.js, 31, 4)) >min : Symbol(min, Decl(a.js, 29, 3), Decl(a.js, 29, 27), Decl(a.js, 30, 44)) >nest : Symbol(min.nest, Decl(a.js, 29, 27), Decl(a.js, 31, 4)) +>this.min.nest : Symbol(min.nest, Decl(a.js, 29, 27), Decl(a.js, 31, 4)) +>this.min : Symbol(min, Decl(a.js, 29, 3), Decl(a.js, 29, 27), Decl(a.js, 30, 44)) +>this : Symbol(globalThis) +>min : Symbol(min, Decl(a.js, 29, 3), Decl(a.js, 29, 27), Decl(a.js, 30, 44)) +>nest : Symbol(min.nest, Decl(a.js, 29, 27), Decl(a.js, 31, 4)) min.nest.other = self.min.nest.other || class { }; >min.nest.other : Symbol(min.nest.other, Decl(a.js, 30, 44)) diff --git a/tests/baselines/reference/typeFromPropertyAssignment9.types b/tests/baselines/reference/typeFromPropertyAssignment9.types index b212f12bb17..c4f813f0a89 100644 --- a/tests/baselines/reference/typeFromPropertyAssignment9.types +++ b/tests/baselines/reference/typeFromPropertyAssignment9.types @@ -157,11 +157,11 @@ min.nest = this.min.nest || function () { }; >min : typeof min >nest : { (): void; other: typeof other; } >this.min.nest || function () { } : { (): void; other: typeof other; } ->this.min.nest : any ->this.min : any ->this : any ->min : any ->nest : any +>this.min.nest : { (): void; other: typeof other; } +>this.min : typeof min +>this : typeof globalThis +>min : typeof min +>nest : { (): void; other: typeof other; } >function () { } : { (): void; other: typeof other; } min.nest.other = self.min.nest.other || class { }; diff --git a/tests/baselines/reference/typeOfThis.errors.txt b/tests/baselines/reference/typeOfThis.errors.txt index 83d450570fc..b47207670cc 100644 --- a/tests/baselines/reference/typeOfThis.errors.txt +++ b/tests/baselines/reference/typeOfThis.errors.txt @@ -1,24 +1,16 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(14,13): error TS2403: Subsequent variable declarations must have the same type. Variable 't' must be of type 'this', but here has type 'MyTestClass'. tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(18,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'p' must be of type 'this', but here has type 'MyTestClass'. -tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(22,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(24,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'p' must be of type 'this', but here has type 'MyTestClass'. -tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(27,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(29,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'p' must be of type 'this', but here has type 'MyTestClass'. tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(37,13): error TS2403: Subsequent variable declarations must have the same type. Variable 't' must be of type 'this', but here has type 'MyTestClass'. -tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(53,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(61,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(83,13): error TS2403: Subsequent variable declarations must have the same type. Variable 't' must be of type 'this', but here has type 'MyGenericTestClass'. tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(87,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'p' must be of type 'this', but here has type 'MyGenericTestClass'. -tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(91,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(93,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'p' must be of type 'this', but here has type 'MyGenericTestClass'. -tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(96,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(98,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'p' must be of type 'this', but here has type 'MyGenericTestClass'. tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(106,13): error TS2403: Subsequent variable declarations must have the same type. Variable 't' must be of type 'this', but here has type 'MyGenericTestClass'. -tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(122,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(130,16): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -==== tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts (18 errors) ==== +==== tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts (10 errors) ==== class MyTestClass { private canary: number; static staticCanary: number; @@ -45,8 +37,6 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(130,16): error TS1 //type of 'this' in member accessor(get and set) body is the class instance type get prop() { - ~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. var p = this; var p: MyTestClass; ~ @@ -54,8 +44,6 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(130,16): error TS1 return this; } set prop(v) { - ~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. var p = this; var p: MyTestClass; ~ @@ -86,8 +74,6 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(130,16): error TS1 } static get staticProp() { - ~~~~~~~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. //type of 'this' in static accessor body is constructor function type var p = this; var p: typeof MyTestClass; @@ -96,8 +82,6 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(130,16): error TS1 return this; } static set staticProp(v: typeof MyTestClass) { - ~~~~~~~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. //type of 'this' in static accessor body is constructor function type var p = this; var p: typeof MyTestClass; @@ -132,8 +116,6 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(130,16): error TS1 //type of 'this' in member accessor(get and set) body is the class instance type get prop() { - ~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. var p = this; var p: MyGenericTestClass; ~ @@ -141,8 +123,6 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(130,16): error TS1 return this; } set prop(v) { - ~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. var p = this; var p: MyGenericTestClass; ~ @@ -173,8 +153,6 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(130,16): error TS1 } static get staticProp() { - ~~~~~~~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. //type of 'this' in static accessor body is constructor function type var p = this; var p: typeof MyGenericTestClass; @@ -183,8 +161,6 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(130,16): error TS1 return this; } static set staticProp(v: typeof MyGenericTestClass) { - ~~~~~~~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. //type of 'this' in static accessor body is constructor function type var p = this; var p: typeof MyGenericTestClass; @@ -215,19 +191,19 @@ tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts(130,16): error TS1 this.spaaaaace = 4; } - //type of 'this' in a fat arrow expression param list is Any + //type of 'this' in a fat arrow expression param list is typeof globalThis var q2 = (s = this) => { - var s: any; + var s: typeof globalThis; s.spaaaaaaace = 4; - //type of 'this' in a fat arrow expression body is Any - var t: any; + //type of 'this' in a fat arrow expression body is typeof globalThis + var t: typeof globalThis; var t = this; this.spaaaaace = 4; } - //type of 'this' in global module is Any - var t: any; + //type of 'this' in global module is GlobalThis + var t: typeof globalThis; var t = this; this.spaaaaace = 4; diff --git a/tests/baselines/reference/typeOfThis.js b/tests/baselines/reference/typeOfThis.js index 42593bd3d2a..0ea8fc2f935 100644 --- a/tests/baselines/reference/typeOfThis.js +++ b/tests/baselines/reference/typeOfThis.js @@ -159,32 +159,30 @@ var q1 = function (s = this) { this.spaaaaace = 4; } -//type of 'this' in a fat arrow expression param list is Any +//type of 'this' in a fat arrow expression param list is typeof globalThis var q2 = (s = this) => { - var s: any; + var s: typeof globalThis; s.spaaaaaaace = 4; - //type of 'this' in a fat arrow expression body is Any - var t: any; + //type of 'this' in a fat arrow expression body is typeof globalThis + var t: typeof globalThis; var t = this; this.spaaaaace = 4; } -//type of 'this' in global module is Any -var t: any; +//type of 'this' in global module is GlobalThis +var t: typeof globalThis; var t = this; this.spaaaaace = 4; //// [typeOfThis.js] -var _this = this; -var MyTestClass = /** @class */ (function () { - function MyTestClass() { - var _this = this; - this.someFunc = function () { +class MyTestClass { + constructor() { + this.someFunc = () => { //type of 'this' in member variable initializer is the class instance type - var t = _this; + var t = this; var t; }; //type of 'this' in constructor body is the class instance type @@ -193,32 +191,26 @@ var MyTestClass = /** @class */ (function () { this.canary = 3; } //type of 'this' in member function param list is the class instance type - MyTestClass.prototype.memberFunc = function (t) { - if (t === void 0) { t = this; } + memberFunc(t = this) { var t; //type of 'this' in member function body is the class instance type var p = this; var p; - }; - Object.defineProperty(MyTestClass.prototype, "prop", { - //type of 'this' in member accessor(get and set) body is the class instance type - get: function () { - var p = this; - var p; - return this; - }, - set: function (v) { - var p = this; - var p; - p = v; - v = p; - }, - enumerable: true, - configurable: true - }); + } + //type of 'this' in member accessor(get and set) body is the class instance type + get prop() { + var p = this; + var p; + return this; + } + set prop(v) { + var p = this; + var p; + p = v; + v = p; + } //type of 'this' in static function param list is constructor function type - MyTestClass.staticFn = function (t) { - if (t === void 0) { t = this; } + static staticFn(t = this) { var t; var t = MyTestClass; t.staticCanary; @@ -227,34 +219,28 @@ var MyTestClass = /** @class */ (function () { var p; var p = MyTestClass; p.staticCanary; - }; - Object.defineProperty(MyTestClass, "staticProp", { - get: function () { - //type of 'this' in static accessor body is constructor function type - var p = this; - var p; - var p = MyTestClass; - p.staticCanary; - return this; - }, - set: function (v) { - //type of 'this' in static accessor body is constructor function type - var p = this; - var p; - var p = MyTestClass; - p.staticCanary; - }, - enumerable: true, - configurable: true - }); - return MyTestClass; -}()); -var MyGenericTestClass = /** @class */ (function () { - function MyGenericTestClass() { - var _this = this; - this.someFunc = function () { + } + static get staticProp() { + //type of 'this' in static accessor body is constructor function type + var p = this; + var p; + var p = MyTestClass; + p.staticCanary; + return this; + } + static set staticProp(v) { + //type of 'this' in static accessor body is constructor function type + var p = this; + var p; + var p = MyTestClass; + p.staticCanary; + } +} +class MyGenericTestClass { + constructor() { + this.someFunc = () => { //type of 'this' in member variable initializer is the class instance type - var t = _this; + var t = this; var t; }; //type of 'this' in constructor body is the class instance type @@ -263,32 +249,26 @@ var MyGenericTestClass = /** @class */ (function () { this.canary = 3; } //type of 'this' in member function param list is the class instance type - MyGenericTestClass.prototype.memberFunc = function (t) { - if (t === void 0) { t = this; } + memberFunc(t = this) { var t; //type of 'this' in member function body is the class instance type var p = this; var p; - }; - Object.defineProperty(MyGenericTestClass.prototype, "prop", { - //type of 'this' in member accessor(get and set) body is the class instance type - get: function () { - var p = this; - var p; - return this; - }, - set: function (v) { - var p = this; - var p; - p = v; - v = p; - }, - enumerable: true, - configurable: true - }); + } + //type of 'this' in member accessor(get and set) body is the class instance type + get prop() { + var p = this; + var p; + return this; + } + set prop(v) { + var p = this; + var p; + p = v; + v = p; + } //type of 'this' in static function param list is constructor function type - MyGenericTestClass.staticFn = function (t) { - if (t === void 0) { t = this; } + static staticFn(t = this) { var t; var t = MyGenericTestClass; t.staticCanary; @@ -297,31 +277,25 @@ var MyGenericTestClass = /** @class */ (function () { var p; var p = MyGenericTestClass; p.staticCanary; - }; - Object.defineProperty(MyGenericTestClass, "staticProp", { - get: function () { - //type of 'this' in static accessor body is constructor function type - var p = this; - var p; - var p = MyGenericTestClass; - p.staticCanary; - return this; - }, - set: function (v) { - //type of 'this' in static accessor body is constructor function type - var p = this; - var p; - var p = MyGenericTestClass; - p.staticCanary; - }, - enumerable: true, - configurable: true - }); - return MyGenericTestClass; -}()); + } + static get staticProp() { + //type of 'this' in static accessor body is constructor function type + var p = this; + var p; + var p = MyGenericTestClass; + p.staticCanary; + return this; + } + static set staticProp(v) { + //type of 'this' in static accessor body is constructor function type + var p = this; + var p; + var p = MyGenericTestClass; + p.staticCanary; + } +} //type of 'this' in a function declaration param list is Any -function fn(s) { - if (s === void 0) { s = this; } +function fn(s = this) { var s; s.spaaaaaaace = 4; //type of 'this' in a function declaration body is Any @@ -330,8 +304,7 @@ function fn(s) { this.spaaaaace = 4; } //type of 'this' in a function expression param list list is Any -var q1 = function (s) { - if (s === void 0) { s = this; } +var q1 = function (s = this) { var s; s.spaaaaaaace = 4; //type of 'this' in a function expression body is Any @@ -339,17 +312,16 @@ var q1 = function (s) { var t = this; this.spaaaaace = 4; }; -//type of 'this' in a fat arrow expression param list is Any -var q2 = function (s) { - if (s === void 0) { s = _this; } +//type of 'this' in a fat arrow expression param list is typeof globalThis +var q2 = (s = this) => { var s; s.spaaaaaaace = 4; - //type of 'this' in a fat arrow expression body is Any + //type of 'this' in a fat arrow expression body is typeof globalThis var t; - var t = _this; - _this.spaaaaace = 4; + var t = this; + this.spaaaaace = 4; }; -//type of 'this' in global module is Any +//type of 'this' in global module is GlobalThis var t; var t = this; this.spaaaaace = 4; diff --git a/tests/baselines/reference/typeOfThis.symbols b/tests/baselines/reference/typeOfThis.symbols index c89796f8157..11c2ae273c4 100644 --- a/tests/baselines/reference/typeOfThis.symbols +++ b/tests/baselines/reference/typeOfThis.symbols @@ -419,34 +419,42 @@ var q1 = function (s = this) { this.spaaaaace = 4; } -//type of 'this' in a fat arrow expression param list is Any +//type of 'this' in a fat arrow expression param list is typeof globalThis var q2 = (s = this) => { >q2 : Symbol(q2, Decl(typeOfThis.ts, 161, 3)) >s : Symbol(s, Decl(typeOfThis.ts, 161, 10), Decl(typeOfThis.ts, 162, 7)) +>this : Symbol(globalThis) - var s: any; + var s: typeof globalThis; >s : Symbol(s, Decl(typeOfThis.ts, 161, 10), Decl(typeOfThis.ts, 162, 7)) +>globalThis : Symbol(globalThis) s.spaaaaaaace = 4; >s : Symbol(s, Decl(typeOfThis.ts, 161, 10), Decl(typeOfThis.ts, 162, 7)) - //type of 'this' in a fat arrow expression body is Any - var t: any; + //type of 'this' in a fat arrow expression body is typeof globalThis + var t: typeof globalThis; >t : Symbol(t, Decl(typeOfThis.ts, 166, 7), Decl(typeOfThis.ts, 167, 7)) +>globalThis : Symbol(globalThis) var t = this; >t : Symbol(t, Decl(typeOfThis.ts, 166, 7), Decl(typeOfThis.ts, 167, 7)) +>this : Symbol(globalThis) this.spaaaaace = 4; +>this : Symbol(globalThis) } -//type of 'this' in global module is Any -var t: any; +//type of 'this' in global module is GlobalThis +var t: typeof globalThis; >t : Symbol(t, Decl(typeOfThis.ts, 172, 3), Decl(typeOfThis.ts, 173, 3)) +>globalThis : Symbol(globalThis) var t = this; >t : Symbol(t, Decl(typeOfThis.ts, 172, 3), Decl(typeOfThis.ts, 173, 3)) +>this : Symbol(globalThis) this.spaaaaace = 4; +>this : Symbol(globalThis) diff --git a/tests/baselines/reference/typeOfThis.types b/tests/baselines/reference/typeOfThis.types index 0d27690a49a..9f10153eb97 100644 --- a/tests/baselines/reference/typeOfThis.types +++ b/tests/baselines/reference/typeOfThis.types @@ -430,51 +430,54 @@ var q1 = function (s = this) { >4 : 4 } -//type of 'this' in a fat arrow expression param list is Any +//type of 'this' in a fat arrow expression param list is typeof globalThis var q2 = (s = this) => { ->q2 : (s?: any) => void ->(s = this) => { var s: any; s.spaaaaaaace = 4; //type of 'this' in a fat arrow expression body is Any var t: any; var t = this; this.spaaaaace = 4;} : (s?: any) => void ->s : any ->this : any +>q2 : (s?: typeof globalThis) => void +>(s = this) => { var s: typeof globalThis; s.spaaaaaaace = 4; //type of 'this' in a fat arrow expression body is typeof globalThis var t: typeof globalThis; var t = this; this.spaaaaace = 4;} : (s?: typeof globalThis) => void +>s : typeof globalThis +>this : typeof globalThis - var s: any; ->s : any + var s: typeof globalThis; +>s : typeof globalThis +>globalThis : typeof globalThis s.spaaaaaaace = 4; >s.spaaaaaaace = 4 : 4 >s.spaaaaaaace : any ->s : any +>s : typeof globalThis >spaaaaaaace : any >4 : 4 - //type of 'this' in a fat arrow expression body is Any - var t: any; ->t : any + //type of 'this' in a fat arrow expression body is typeof globalThis + var t: typeof globalThis; +>t : typeof globalThis +>globalThis : typeof globalThis var t = this; ->t : any ->this : any +>t : typeof globalThis +>this : typeof globalThis this.spaaaaace = 4; >this.spaaaaace = 4 : 4 >this.spaaaaace : any ->this : any +>this : typeof globalThis >spaaaaace : any >4 : 4 } -//type of 'this' in global module is Any -var t: any; ->t : any +//type of 'this' in global module is GlobalThis +var t: typeof globalThis; +>t : typeof globalThis +>globalThis : typeof globalThis var t = this; ->t : any ->this : any +>t : typeof globalThis +>this : typeof globalThis this.spaaaaace = 4; >this.spaaaaace = 4 : 4 >this.spaaaaace : any ->this : any +>this : typeof globalThis >spaaaaace : any >4 : 4 diff --git a/tests/baselines/reference/unknownSymbols1.symbols b/tests/baselines/reference/unknownSymbols1.symbols index d9726011f1a..c6f67db4a1d 100644 --- a/tests/baselines/reference/unknownSymbols1.symbols +++ b/tests/baselines/reference/unknownSymbols1.symbols @@ -54,6 +54,7 @@ class C4 extends C3 { var x2 = this.asdf; // no error, this is any >x2 : Symbol(x2, Decl(unknownSymbols1.ts, 25, 3)) +>this : Symbol(globalThis) class C5 { >C5 : Symbol(C5, Decl(unknownSymbols1.ts, 25, 19)) diff --git a/tests/baselines/reference/unknownSymbols1.types b/tests/baselines/reference/unknownSymbols1.types index f4532733485..9fced36d703 100644 --- a/tests/baselines/reference/unknownSymbols1.types +++ b/tests/baselines/reference/unknownSymbols1.types @@ -57,7 +57,7 @@ class C4 extends C3 { var x2 = this.asdf; // no error, this is any >x2 : any >this.asdf : any ->this : any +>this : typeof globalThis >asdf : any class C5 { diff --git a/tests/baselines/reference/wrappedIncovations1.symbols b/tests/baselines/reference/wrappedIncovations1.symbols index 49ccc1fa896..09493341040 100644 --- a/tests/baselines/reference/wrappedIncovations1.symbols +++ b/tests/baselines/reference/wrappedIncovations1.symbols @@ -1,6 +1,7 @@ === tests/cases/compiler/wrappedIncovations1.ts === var v = this >v : Symbol(v, Decl(wrappedIncovations1.ts, 0, 3)) +>this : Symbol(globalThis) .foo() .bar() diff --git a/tests/baselines/reference/wrappedIncovations1.types b/tests/baselines/reference/wrappedIncovations1.types index 32f7bb0e1b8..92adf203aa9 100644 --- a/tests/baselines/reference/wrappedIncovations1.types +++ b/tests/baselines/reference/wrappedIncovations1.types @@ -7,7 +7,7 @@ var v = this >this .foo() .bar : any >this .foo() : any >this .foo : any ->this : any +>this : typeof globalThis .foo() >foo : any diff --git a/tests/baselines/reference/wrappedIncovations2.symbols b/tests/baselines/reference/wrappedIncovations2.symbols index 2836bf7c19c..6e5dcf7aae2 100644 --- a/tests/baselines/reference/wrappedIncovations2.symbols +++ b/tests/baselines/reference/wrappedIncovations2.symbols @@ -1,6 +1,7 @@ === tests/cases/compiler/wrappedIncovations2.ts === var v = this. >v : Symbol(v, Decl(wrappedIncovations2.ts, 0, 3)) +>this : Symbol(globalThis) foo(). bar(). diff --git a/tests/baselines/reference/wrappedIncovations2.types b/tests/baselines/reference/wrappedIncovations2.types index 96337796bcd..71317c3f9c2 100644 --- a/tests/baselines/reference/wrappedIncovations2.types +++ b/tests/baselines/reference/wrappedIncovations2.types @@ -7,7 +7,7 @@ var v = this. >this. foo(). bar : any >this. foo() : any >this. foo : any ->this : any +>this : typeof globalThis foo(). >foo : any diff --git a/tests/cases/conformance/es2019/globalThisPropertyAssignment.ts b/tests/cases/conformance/es2019/globalThisPropertyAssignment.ts new file mode 100644 index 00000000000..fb9638e30fb --- /dev/null +++ b/tests/cases/conformance/es2019/globalThisPropertyAssignment.ts @@ -0,0 +1,10 @@ +// @allowJs: true +// @checkJs: true +// @noEmit: true +// @Filename: globalThisPropertyAssignment.js +this.x = 1 +var y = 2 +// should work in JS +window.z = 3 +// should work in JS (even though it's a secondary declaration) +globalThis.alpha = 4 diff --git a/tests/cases/conformance/es2019/globalThisReadonlyProperties.ts b/tests/cases/conformance/es2019/globalThisReadonlyProperties.ts new file mode 100644 index 00000000000..f641fe8d0da --- /dev/null +++ b/tests/cases/conformance/es2019/globalThisReadonlyProperties.ts @@ -0,0 +1,5 @@ +globalThis.globalThis = 1 as any // should error +var x = 1 +const y = 2 +globalThis.x = 3 +globalThis.y = 4 // should error diff --git a/tests/cases/conformance/es2019/globalThisTypeIndexAccess.ts b/tests/cases/conformance/es2019/globalThisTypeIndexAccess.ts new file mode 100644 index 00000000000..88f68f8f884 --- /dev/null +++ b/tests/cases/conformance/es2019/globalThisTypeIndexAccess.ts @@ -0,0 +1,2 @@ + +declare const w_e: (typeof globalThis)["globalThis"] diff --git a/tests/cases/conformance/es2019/globalThisUnknown.ts b/tests/cases/conformance/es2019/globalThisUnknown.ts new file mode 100644 index 00000000000..b1ae4224e1e --- /dev/null +++ b/tests/cases/conformance/es2019/globalThisUnknown.ts @@ -0,0 +1,13 @@ +declare let win: Window & typeof globalThis; + +// this access should be an error +win.hi +// these two should be fine, with type any +this.hi +globalThis.hi + +// element access is always ok without noImplicitAny +win['hi'] +this['hi'] +globalThis['hi'] + diff --git a/tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts b/tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts new file mode 100644 index 00000000000..53fb9a98edb --- /dev/null +++ b/tests/cases/conformance/es2019/globalThisUnknownNoImplicitAny.ts @@ -0,0 +1,11 @@ +// @noImplicitAny: true +declare let win: Window & typeof globalThis; + +// all accesses should be errors +win.hi +this.hi +globalThis.hi + +win['hi'] +this['hi'] +globalThis['hi'] diff --git a/tests/cases/conformance/es2019/globalThisVarDeclaration.ts b/tests/cases/conformance/es2019/globalThisVarDeclaration.ts new file mode 100644 index 00000000000..5b75d1095a6 --- /dev/null +++ b/tests/cases/conformance/es2019/globalThisVarDeclaration.ts @@ -0,0 +1,35 @@ +// @out: output.js +// @target: esnext +// @lib: esnext, dom +// @Filename: b.js +// @allowJs: true +// @checkJs: true +var a = 10; +this.a; +this.b; +globalThis.a; +globalThis.b; + +// DOM access is not supported until the index signature is handled more strictly +self.a; +self.b; +window.a; +window.b; +top.a; +top.b; + +// @Filename: actual.ts +var b = 10; +this.a; +this.b; +globalThis.a; +globalThis.b; + +// same here -- no DOM access to globalThis yet +self.a; +self.b; +window.a; +window.b; +top.a; +top.b; + diff --git a/tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts b/tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts index 4e9da72af6d..3a793f1f391 100644 --- a/tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts +++ b/tests/cases/conformance/expressions/thisKeyword/typeOfThis.ts @@ -1,3 +1,4 @@ +// @target: esnext class MyTestClass { private canary: number; static staticCanary: number; @@ -158,19 +159,19 @@ var q1 = function (s = this) { this.spaaaaace = 4; } -//type of 'this' in a fat arrow expression param list is Any +//type of 'this' in a fat arrow expression param list is typeof globalThis var q2 = (s = this) => { - var s: any; + var s: typeof globalThis; s.spaaaaaaace = 4; - //type of 'this' in a fat arrow expression body is Any - var t: any; + //type of 'this' in a fat arrow expression body is typeof globalThis + var t: typeof globalThis; var t = this; this.spaaaaace = 4; } -//type of 'this' in global module is Any -var t: any; +//type of 'this' in global module is GlobalThis +var t: typeof globalThis; var t = this; this.spaaaaace = 4; diff --git a/tests/cases/conformance/salsa/topLevelThisAssignment.ts b/tests/cases/conformance/salsa/topLevelThisAssignment.ts index 162bed0c30f..aed2f867108 100644 --- a/tests/cases/conformance/salsa/topLevelThisAssignment.ts +++ b/tests/cases/conformance/salsa/topLevelThisAssignment.ts @@ -1,5 +1,6 @@ // @out: output.js // @allowJs: true +// @checkJs: true // @Filename: a.js this.a = 10; this.a; diff --git a/tests/cases/fourslash/completionEntryForClassMembers.ts b/tests/cases/fourslash/completionEntryForClassMembers.ts index 9da74be0bb1..6dcfd059c46 100644 --- a/tests/cases/fourslash/completionEntryForClassMembers.ts +++ b/tests/cases/fourslash/completionEntryForClassMembers.ts @@ -130,6 +130,7 @@ verify.completions( marker: "InsideMethod", exact: [ "arguments", + "globalThis", "B", "C", "D", "D1", "D2", "D3", "D4", "D5", "D6", "E", "F", "F2", "G", "G2", "H", "I", "J", "K", "L", "L2", "M", "N", "O", "undefined", ...completion.insideMethodKeywords, diff --git a/tests/cases/fourslash/completionListIsGlobalCompletion.ts b/tests/cases/fourslash/completionListIsGlobalCompletion.ts index f8ee9430537..2a37849c2b8 100644 --- a/tests/cases/fourslash/completionListIsGlobalCompletion.ts +++ b/tests/cases/fourslash/completionListIsGlobalCompletion.ts @@ -47,6 +47,6 @@ verify.completions( { marker: "10", exact: completion.classElementKeywords, isGlobalCompletion: false, isNewIdentifierLocation: true }, { marker: "13", exact: globals, isGlobalCompletion: false }, { marker: "15", exact: globals, isGlobalCompletion: true, isNewIdentifierLocation: true }, - { marker: "16", exact: [...x, ...completion.globalsVars, "undefined"], isGlobalCompletion: false }, + { marker: "16", exact: [...x, "globalThis", ...completion.globalsVars, "undefined"], isGlobalCompletion: false }, { marker: "17", exact: completion.globalKeywordsPlusUndefined, isGlobalCompletion: false }, ); diff --git a/tests/cases/fourslash/completionListKeywords.ts b/tests/cases/fourslash/completionListKeywords.ts index 660099d3188..ed489487b3c 100644 --- a/tests/cases/fourslash/completionListKeywords.ts +++ b/tests/cases/fourslash/completionListKeywords.ts @@ -4,4 +4,4 @@ /////**/ -verify.completions({ marker: "", exact: ["undefined", ...completion.statementKeywordsWithTypes] }); +verify.completions({ marker: "", exact: ["globalThis", "undefined", ...completion.statementKeywordsWithTypes] }); diff --git a/tests/cases/fourslash/completionListWithMeanings.ts b/tests/cases/fourslash/completionListWithMeanings.ts index 8c3498ebda5..41df1ed3816 100644 --- a/tests/cases/fourslash/completionListWithMeanings.ts +++ b/tests/cases/fourslash/completionListWithMeanings.ts @@ -16,6 +16,7 @@ ////var zz = { x: 4, y: 3 }; const values: ReadonlyArray = [ + "globalThis", { name: "m2", text: "namespace m2" }, // With no type side, allowed only in value { name: "m3", text: "namespace m3" }, { name: "xx", text: "var xx: number" }, @@ -28,6 +29,7 @@ const values: ReadonlyArray = [ ]; const types: ReadonlyArray = [ + "globalThis", { name: "m", text: "namespace m" }, { name: "m3", text: "namespace m3" }, { name: "point", text: "interface point" }, diff --git a/tests/cases/fourslash/completionListWithModulesFromModule.ts b/tests/cases/fourslash/completionListWithModulesFromModule.ts index d08e26a8d50..dbcbdd79783 100644 --- a/tests/cases/fourslash/completionListWithModulesFromModule.ts +++ b/tests/cases/fourslash/completionListWithModulesFromModule.ts @@ -263,6 +263,7 @@ verify.completions( { name: "shwvar", text: "var shwvar: string" }, { name: "shwcls", text: "class shwcls" }, "tmp", + "globalThis", ...commonValues, "undefined", ...completion.statementKeywordsWithTypes, @@ -272,6 +273,7 @@ verify.completions( exact: [ { name: "shwcls", text: "class shwcls" }, { name: "shwint", text: "interface shwint" }, + "globalThis", ...commonTypes, ...completion.typeKeywords, ] @@ -282,6 +284,7 @@ verify.completions( "Mod1", "iMod1", "tmp", + "globalThis", { name: "shwfn", text: "function shwfn(): void" }, ...commonValues, { name: "shwcls", text: "class shwcls" }, @@ -295,6 +298,7 @@ verify.completions( exact: [ "Mod1", "iMod1", + "globalThis", ...commonTypes, { name: "shwcls", text: "class shwcls" }, { name: "shwint", text: "interface shwint" }, diff --git a/tests/cases/fourslash/completionsImport_default_anonymous.ts b/tests/cases/fourslash/completionsImport_default_anonymous.ts index 8aa9dfb5af6..720bb3f1c6b 100644 --- a/tests/cases/fourslash/completionsImport_default_anonymous.ts +++ b/tests/cases/fourslash/completionsImport_default_anonymous.ts @@ -14,7 +14,7 @@ goTo.marker("0"); const preferences: FourSlashInterface.UserPreferences = { includeCompletionsForModuleExports: true }; verify.completions( - { marker: "0", exact: ["undefined", ...completion.statementKeywordsWithTypes], preferences }, + { marker: "0", exact: ["globalThis", "undefined", ...completion.statementKeywordsWithTypes], preferences }, { marker: "1", includes: { name: "fooBar", source: "/src/foo-bar", sourceDisplay: "./foo-bar", text: "(property) default: 0", kind: "property", hasAction: true }, diff --git a/tests/cases/fourslash/completionsImport_exportEquals_anonymous.ts b/tests/cases/fourslash/completionsImport_exportEquals_anonymous.ts index c5e87877cfb..8fc73457117 100644 --- a/tests/cases/fourslash/completionsImport_exportEquals_anonymous.ts +++ b/tests/cases/fourslash/completionsImport_exportEquals_anonymous.ts @@ -14,7 +14,7 @@ goTo.marker("0"); const preferences: FourSlashInterface.UserPreferences = { includeCompletionsForModuleExports: true }; const exportEntry: FourSlashInterface.ExpectedCompletionEntryObject = { name: "fooBar", source: "/src/foo-bar", sourceDisplay: "./foo-bar", text: "(property) export=: 0", kind: "property", hasAction: true }; verify.completions( - { marker: "0", exact: ["undefined", exportEntry, ...completion.statementKeywordsWithTypes], preferences }, + { marker: "0", exact: ["globalThis", "undefined", exportEntry, ...completion.statementKeywordsWithTypes], preferences }, { marker: "1", includes: exportEntry, preferences } ); verify.applyCodeActionFromCompletion("0", { @@ -25,4 +25,4 @@ verify.applyCodeActionFromCompletion("0", { exp fooB`, -}); \ No newline at end of file +}); diff --git a/tests/cases/fourslash/completionsImport_keywords.ts b/tests/cases/fourslash/completionsImport_keywords.ts index 6d4edd83b36..64bab64c7a8 100644 --- a/tests/cases/fourslash/completionsImport_keywords.ts +++ b/tests/cases/fourslash/completionsImport_keywords.ts @@ -34,7 +34,7 @@ verify.completions( { marker: "unique", exact: [ - ...completion.globalsVars, "undefined", + "globalThis", ...completion.globalsVars, "undefined", { name: "unique", source: "/a", sourceDisplay: "./a", text: "(alias) const unique: 0\nexport unique", hasAction: true }, ...completion.globalKeywords.filter(e => e.name !== "unique"), ], diff --git a/tests/cases/fourslash/completionsImport_multipleWithSameName.ts b/tests/cases/fourslash/completionsImport_multipleWithSameName.ts index ae552f437fe..5893f6f0fdc 100644 --- a/tests/cases/fourslash/completionsImport_multipleWithSameName.ts +++ b/tests/cases/fourslash/completionsImport_multipleWithSameName.ts @@ -20,6 +20,7 @@ goTo.marker(""); verify.completions({ marker: "", exact: [ + "globalThis", { name: "foo", text: "var foo: number", kind: "var", kindModifiers: "declare" }, "undefined", { diff --git a/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts b/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts index 10a0c124e4d..5f21db1e376 100644 --- a/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts +++ b/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts @@ -14,6 +14,7 @@ verify.completions({ marker: "", exact: [ { name: "Test2", text: "(alias) function Test2(): void\nimport Test2", kind: "alias" }, + "globalThis", "undefined", { name: "Test1", source: "/a", sourceDisplay: "./a", text: "function Test1(): void", kind: "function", kindModifiers: "export", hasAction: true }, ...completion.statementKeywordsWithTypes, diff --git a/tests/cases/fourslash/completionsImport_ofAlias_preferShortPath.ts b/tests/cases/fourslash/completionsImport_ofAlias_preferShortPath.ts index f5efa9cd912..71242bc240a 100644 --- a/tests/cases/fourslash/completionsImport_ofAlias_preferShortPath.ts +++ b/tests/cases/fourslash/completionsImport_ofAlias_preferShortPath.ts @@ -19,6 +19,7 @@ verify.completions({ marker: "", exact: [ + "globalThis", "undefined", { name: "foo", source: "/foo/lib/foo", sourceDisplay: "./foo", text: "const foo: 0", kind: "const", kindModifiers: "export", hasAction: true }, ...completion.statementKeywordsWithTypes, diff --git a/tests/cases/fourslash/completionsImport_reExportDefault.ts b/tests/cases/fourslash/completionsImport_reExportDefault.ts index 8e38faa0b05..7f6639c3f13 100644 --- a/tests/cases/fourslash/completionsImport_reExportDefault.ts +++ b/tests/cases/fourslash/completionsImport_reExportDefault.ts @@ -15,6 +15,7 @@ verify.completions({ marker: "", exact: [ + "globalThis", ...completion.globalsVars, "undefined", { diff --git a/tests/cases/fourslash/completionsImport_shadowedByLocal.ts b/tests/cases/fourslash/completionsImport_shadowedByLocal.ts index afe88fa6da8..711386816c0 100644 --- a/tests/cases/fourslash/completionsImport_shadowedByLocal.ts +++ b/tests/cases/fourslash/completionsImport_shadowedByLocal.ts @@ -11,6 +11,6 @@ verify.completions({ marker: "", - exact: [{ name: "foo", text: "const foo: 1" }, "undefined", ...completion.statementKeywordsWithTypes], + exact: ["globalThis", { name: "foo", text: "const foo: 1" }, "undefined", ...completion.statementKeywordsWithTypes], preferences: { includeCompletionsForModuleExports: true }, }); diff --git a/tests/cases/fourslash/completionsTypeKeywords.ts b/tests/cases/fourslash/completionsTypeKeywords.ts index 10a6d453759..4c26e13932e 100644 --- a/tests/cases/fourslash/completionsTypeKeywords.ts +++ b/tests/cases/fourslash/completionsTypeKeywords.ts @@ -6,5 +6,5 @@ verify.completions({ marker: "", - exact: ["T", ...completion.typeKeywords], + exact: ["globalThis", "T", ...completion.typeKeywords], }); diff --git a/tests/cases/fourslash/findAllRefsThisKeyword.ts b/tests/cases/fourslash/findAllRefsThisKeyword.ts index 34995467a27..b0045e91bc1 100644 --- a/tests/cases/fourslash/findAllRefsThisKeyword.ts +++ b/tests/cases/fourslash/findAllRefsThisKeyword.ts @@ -24,8 +24,8 @@ ////const x = { [|{| "isWriteAccess": true, "isDefinition": true |}this|]: 0 } ////x.[|this|]; -const [global, f0, f1, g0, g1, x, y, constructor, method, propDef, propUse] = test.ranges(); -verify.singleReferenceGroup("this", [global]); +const [glob, f0, f1, g0, g1, x, y, constructor, method, propDef, propUse] = test.ranges(); +verify.singleReferenceGroup("this: typeof globalThis", [glob]); verify.singleReferenceGroup("(parameter) this: any", [f0, f1]); verify.singleReferenceGroup("(parameter) this: any", [g0, g1]); verify.singleReferenceGroup("this: typeof C", [x, y]); diff --git a/tests/cases/fourslash/findAllRefsThisKeywordMultipleFiles.ts b/tests/cases/fourslash/findAllRefsThisKeywordMultipleFiles.ts index d94f2993d1d..807bc9bf194 100644 --- a/tests/cases/fourslash/findAllRefsThisKeywordMultipleFiles.ts +++ b/tests/cases/fourslash/findAllRefsThisKeywordMultipleFiles.ts @@ -12,4 +12,4 @@ //// // different 'this' //// function f(this) { return this; } -verify.singleReferenceGroup("this"); +verify.singleReferenceGroup("this: typeof globalThis"); diff --git a/tests/cases/fourslash/tsxCompletionOnOpeningTagWithoutJSX1.ts b/tests/cases/fourslash/tsxCompletionOnOpeningTagWithoutJSX1.ts index 7a577cfbcce..9198f5a857a 100644 --- a/tests/cases/fourslash/tsxCompletionOnOpeningTagWithoutJSX1.ts +++ b/tests/cases/fourslash/tsxCompletionOnOpeningTagWithoutJSX1.ts @@ -3,4 +3,4 @@ //@Filename: file.tsx //// var x = Date: Wed, 27 Feb 2019 14:33:25 -0800 Subject: [PATCH 15/19] Don't crash if someone created a folder while we were checking to see if it exists --- src/compiler/sys.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 33283c93803..6d8c4628092 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -615,7 +615,17 @@ namespace ts { directoryExists, createDirectory(directoryName: string) { if (!nodeSystem.directoryExists(directoryName)) { - _fs.mkdirSync(directoryName); + // Wrapped in a try-catch to prevent crashing if we are in a race + // with another copy of ourselves to create the same directory + try { + _fs.mkdirSync(directoryName); + } + catch (e) { + if (e.code !== "EEXIST") { + // Failed for some other reason (access denied?); still throw + throw e; + } + } } }, getExecutingFilePath() { From a6a3ae00a614ec76272ed101557a5ea121cd81f5 Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 28 Feb 2019 12:46:24 -0800 Subject: [PATCH 16/19] Only collect inferences which actually have inferences into the returnMapper (#30111) --- src/compiler/checker.ts | 21 +++++- .../returnTypeInferenceNotTooBroad.js | 24 +++++++ .../returnTypeInferenceNotTooBroad.symbols | 67 +++++++++++++++++++ .../returnTypeInferenceNotTooBroad.types | 65 ++++++++++++++++++ .../returnTypeInferenceNotTooBroad.ts | 14 ++++ 5 files changed, 189 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/returnTypeInferenceNotTooBroad.js create mode 100644 tests/baselines/reference/returnTypeInferenceNotTooBroad.symbols create mode 100644 tests/baselines/reference/returnTypeInferenceNotTooBroad.types create mode 100644 tests/cases/compiler/returnTypeInferenceNotTooBroad.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cf61c4a97a8..363eeca7894 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -10691,6 +10691,23 @@ namespace ts { mapper; } + function cloneInferredPartOfContext(context: InferenceContext): InferenceContext | undefined { + // Filter context to only those parameters which actually have inference candidates + const params = []; + const inferences = []; + for (let i = 0; i < context.typeParameters.length; i++) { + const info = context.inferences[i]; + if (info.candidates || info.contraCandidates) { + params.push(context.typeParameters[i]); + inferences.push(info); + } + } + if (!params.length) { + return undefined; + } + return createInferenceContext(params, context.signature, context.flags | InferenceFlags.NoDefault, context.compareTypes, inferences); + } + function combineTypeMappers(mapper1: TypeMapper | undefined, mapper2: TypeMapper): TypeMapper; function combineTypeMappers(mapper1: TypeMapper, mapper2: TypeMapper | undefined): TypeMapper; function combineTypeMappers(mapper1: TypeMapper, mapper2: TypeMapper): TypeMapper { @@ -14900,7 +14917,7 @@ namespace ts { // parameter should be instantiated to the empty object type. inferredType = instantiateType(defaultType, combineTypeMappers( - createBackreferenceMapper(context.signature!.typeParameters!, index), + createBackreferenceMapper(context.typeParameters, index), context)); } else { @@ -20069,7 +20086,7 @@ namespace ts { inferTypes(context.inferences, inferenceSourceType, inferenceTargetType, InferencePriority.ReturnType); // Create a type mapper for instantiating generic contextual types using the inferences made // from the return type. - context.returnMapper = cloneTypeMapper(context); + context.returnMapper = cloneInferredPartOfContext(context); } } diff --git a/tests/baselines/reference/returnTypeInferenceNotTooBroad.js b/tests/baselines/reference/returnTypeInferenceNotTooBroad.js new file mode 100644 index 00000000000..74ee34f508b --- /dev/null +++ b/tests/baselines/reference/returnTypeInferenceNotTooBroad.js @@ -0,0 +1,24 @@ +//// [returnTypeInferenceNotTooBroad.ts] +type Signs = { kind: 'a'; a: 3; } | { kind: 'b'; b: 2; } | { kind: 'c'; c: 1; }; +interface Opts { + low?: number; + sign?: T +} +interface Wrapper { +} +declare function sepsis(opts: Opts): Wrapper; +declare function unwrap(w: Wrapper): T; +export const y = sepsis({ low: 1, sign: { kind: 'a', a: 3 }}); +// $ExpectType { kind: "a"; a: 3; } +export const yun = unwrap(y); +// $ExpectType { kind: "a"; a: 3; } +export const yone = unwrap(sepsis({ low: 1, sign: { kind: 'a', a: 3 }})); + +//// [returnTypeInferenceNotTooBroad.js] +"use strict"; +exports.__esModule = true; +exports.y = sepsis({ low: 1, sign: { kind: 'a', a: 3 } }); +// $ExpectType { kind: "a"; a: 3; } +exports.yun = unwrap(exports.y); +// $ExpectType { kind: "a"; a: 3; } +exports.yone = unwrap(sepsis({ low: 1, sign: { kind: 'a', a: 3 } })); diff --git a/tests/baselines/reference/returnTypeInferenceNotTooBroad.symbols b/tests/baselines/reference/returnTypeInferenceNotTooBroad.symbols new file mode 100644 index 00000000000..6a79c2f29e3 --- /dev/null +++ b/tests/baselines/reference/returnTypeInferenceNotTooBroad.symbols @@ -0,0 +1,67 @@ +=== tests/cases/compiler/returnTypeInferenceNotTooBroad.ts === +type Signs = { kind: 'a'; a: 3; } | { kind: 'b'; b: 2; } | { kind: 'c'; c: 1; }; +>Signs : Symbol(Signs, Decl(returnTypeInferenceNotTooBroad.ts, 0, 0)) +>kind : Symbol(kind, Decl(returnTypeInferenceNotTooBroad.ts, 0, 14)) +>a : Symbol(a, Decl(returnTypeInferenceNotTooBroad.ts, 0, 25)) +>kind : Symbol(kind, Decl(returnTypeInferenceNotTooBroad.ts, 0, 37)) +>b : Symbol(b, Decl(returnTypeInferenceNotTooBroad.ts, 0, 48)) +>kind : Symbol(kind, Decl(returnTypeInferenceNotTooBroad.ts, 0, 60)) +>c : Symbol(c, Decl(returnTypeInferenceNotTooBroad.ts, 0, 71)) + +interface Opts { +>Opts : Symbol(Opts, Decl(returnTypeInferenceNotTooBroad.ts, 0, 80)) +>T : Symbol(T, Decl(returnTypeInferenceNotTooBroad.ts, 1, 15)) + + low?: number; +>low : Symbol(Opts.low, Decl(returnTypeInferenceNotTooBroad.ts, 1, 19)) + + sign?: T +>sign : Symbol(Opts.sign, Decl(returnTypeInferenceNotTooBroad.ts, 2, 17)) +>T : Symbol(T, Decl(returnTypeInferenceNotTooBroad.ts, 1, 15)) +} +interface Wrapper { +>Wrapper : Symbol(Wrapper, Decl(returnTypeInferenceNotTooBroad.ts, 4, 1)) +>T : Symbol(T, Decl(returnTypeInferenceNotTooBroad.ts, 5, 18)) +} +declare function sepsis(opts: Opts): Wrapper; +>sepsis : Symbol(sepsis, Decl(returnTypeInferenceNotTooBroad.ts, 6, 1)) +>T : Symbol(T, Decl(returnTypeInferenceNotTooBroad.ts, 7, 24)) +>Signs : Symbol(Signs, Decl(returnTypeInferenceNotTooBroad.ts, 0, 0)) +>opts : Symbol(opts, Decl(returnTypeInferenceNotTooBroad.ts, 7, 41)) +>Opts : Symbol(Opts, Decl(returnTypeInferenceNotTooBroad.ts, 0, 80)) +>T : Symbol(T, Decl(returnTypeInferenceNotTooBroad.ts, 7, 24)) +>Wrapper : Symbol(Wrapper, Decl(returnTypeInferenceNotTooBroad.ts, 4, 1)) +>T : Symbol(T, Decl(returnTypeInferenceNotTooBroad.ts, 7, 24)) + +declare function unwrap(w: Wrapper): T; +>unwrap : Symbol(unwrap, Decl(returnTypeInferenceNotTooBroad.ts, 7, 68)) +>T : Symbol(T, Decl(returnTypeInferenceNotTooBroad.ts, 8, 24)) +>w : Symbol(w, Decl(returnTypeInferenceNotTooBroad.ts, 8, 27)) +>Wrapper : Symbol(Wrapper, Decl(returnTypeInferenceNotTooBroad.ts, 4, 1)) +>T : Symbol(T, Decl(returnTypeInferenceNotTooBroad.ts, 8, 24)) +>T : Symbol(T, Decl(returnTypeInferenceNotTooBroad.ts, 8, 24)) + +export const y = sepsis({ low: 1, sign: { kind: 'a', a: 3 }}); +>y : Symbol(y, Decl(returnTypeInferenceNotTooBroad.ts, 9, 12)) +>sepsis : Symbol(sepsis, Decl(returnTypeInferenceNotTooBroad.ts, 6, 1)) +>low : Symbol(low, Decl(returnTypeInferenceNotTooBroad.ts, 9, 25)) +>sign : Symbol(sign, Decl(returnTypeInferenceNotTooBroad.ts, 9, 33)) +>kind : Symbol(kind, Decl(returnTypeInferenceNotTooBroad.ts, 9, 41)) +>a : Symbol(a, Decl(returnTypeInferenceNotTooBroad.ts, 9, 52)) + +// $ExpectType { kind: "a"; a: 3; } +export const yun = unwrap(y); +>yun : Symbol(yun, Decl(returnTypeInferenceNotTooBroad.ts, 11, 12)) +>unwrap : Symbol(unwrap, Decl(returnTypeInferenceNotTooBroad.ts, 7, 68)) +>y : Symbol(y, Decl(returnTypeInferenceNotTooBroad.ts, 9, 12)) + +// $ExpectType { kind: "a"; a: 3; } +export const yone = unwrap(sepsis({ low: 1, sign: { kind: 'a', a: 3 }})); +>yone : Symbol(yone, Decl(returnTypeInferenceNotTooBroad.ts, 13, 12)) +>unwrap : Symbol(unwrap, Decl(returnTypeInferenceNotTooBroad.ts, 7, 68)) +>sepsis : Symbol(sepsis, Decl(returnTypeInferenceNotTooBroad.ts, 6, 1)) +>low : Symbol(low, Decl(returnTypeInferenceNotTooBroad.ts, 13, 35)) +>sign : Symbol(sign, Decl(returnTypeInferenceNotTooBroad.ts, 13, 43)) +>kind : Symbol(kind, Decl(returnTypeInferenceNotTooBroad.ts, 13, 51)) +>a : Symbol(a, Decl(returnTypeInferenceNotTooBroad.ts, 13, 62)) + diff --git a/tests/baselines/reference/returnTypeInferenceNotTooBroad.types b/tests/baselines/reference/returnTypeInferenceNotTooBroad.types new file mode 100644 index 00000000000..a95d7012d17 --- /dev/null +++ b/tests/baselines/reference/returnTypeInferenceNotTooBroad.types @@ -0,0 +1,65 @@ +=== tests/cases/compiler/returnTypeInferenceNotTooBroad.ts === +type Signs = { kind: 'a'; a: 3; } | { kind: 'b'; b: 2; } | { kind: 'c'; c: 1; }; +>Signs : Signs +>kind : "a" +>a : 3 +>kind : "b" +>b : 2 +>kind : "c" +>c : 1 + +interface Opts { + low?: number; +>low : number + + sign?: T +>sign : T +} +interface Wrapper { +} +declare function sepsis(opts: Opts): Wrapper; +>sepsis : (opts: Opts) => Wrapper +>opts : Opts + +declare function unwrap(w: Wrapper): T; +>unwrap : (w: Wrapper) => T +>w : Wrapper + +export const y = sepsis({ low: 1, sign: { kind: 'a', a: 3 }}); +>y : Wrapper<{ kind: "a"; a: 3; }> +>sepsis({ low: 1, sign: { kind: 'a', a: 3 }}) : Wrapper<{ kind: "a"; a: 3; }> +>sepsis : (opts: Opts) => Wrapper +>{ low: 1, sign: { kind: 'a', a: 3 }} : { low: number; sign: { kind: "a"; a: 3; }; } +>low : number +>1 : 1 +>sign : { kind: "a"; a: 3; } +>{ kind: 'a', a: 3 } : { kind: "a"; a: 3; } +>kind : "a" +>'a' : "a" +>a : 3 +>3 : 3 + +// $ExpectType { kind: "a"; a: 3; } +export const yun = unwrap(y); +>yun : { kind: "a"; a: 3; } +>unwrap(y) : { kind: "a"; a: 3; } +>unwrap : (w: Wrapper) => T +>y : Wrapper<{ kind: "a"; a: 3; }> + +// $ExpectType { kind: "a"; a: 3; } +export const yone = unwrap(sepsis({ low: 1, sign: { kind: 'a', a: 3 }})); +>yone : { kind: "a"; a: 3; } +>unwrap(sepsis({ low: 1, sign: { kind: 'a', a: 3 }})) : { kind: "a"; a: 3; } +>unwrap : (w: Wrapper) => T +>sepsis({ low: 1, sign: { kind: 'a', a: 3 }}) : Wrapper<{ kind: "a"; a: 3; }> +>sepsis : (opts: Opts) => Wrapper +>{ low: 1, sign: { kind: 'a', a: 3 }} : { low: number; sign: { kind: "a"; a: 3; }; } +>low : number +>1 : 1 +>sign : { kind: "a"; a: 3; } +>{ kind: 'a', a: 3 } : { kind: "a"; a: 3; } +>kind : "a" +>'a' : "a" +>a : 3 +>3 : 3 + diff --git a/tests/cases/compiler/returnTypeInferenceNotTooBroad.ts b/tests/cases/compiler/returnTypeInferenceNotTooBroad.ts new file mode 100644 index 00000000000..1573b3d72e0 --- /dev/null +++ b/tests/cases/compiler/returnTypeInferenceNotTooBroad.ts @@ -0,0 +1,14 @@ +type Signs = { kind: 'a'; a: 3; } | { kind: 'b'; b: 2; } | { kind: 'c'; c: 1; }; +interface Opts { + low?: number; + sign?: T +} +interface Wrapper { +} +declare function sepsis(opts: Opts): Wrapper; +declare function unwrap(w: Wrapper): T; +export const y = sepsis({ low: 1, sign: { kind: 'a', a: 3 }}); +// $ExpectType { kind: "a"; a: 3; } +export const yun = unwrap(y); +// $ExpectType { kind: "a"; a: 3; } +export const yone = unwrap(sepsis({ low: 1, sign: { kind: 'a', a: 3 }})); \ No newline at end of file From b1a73ab560ef0f0a681f7aa171b349d05a16e00b Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 28 Feb 2019 13:52:57 -0800 Subject: [PATCH 17/19] Resolve aliases to jsx namespace symbol (#30160) --- src/compiler/checker.ts | 2 +- .../reference/jsxNamespaceReexports.js | 32 +++++++++++++++++++ .../reference/jsxNamespaceReexports.symbols | 31 ++++++++++++++++++ .../reference/jsxNamespaceReexports.types | 27 ++++++++++++++++ .../cases/compiler/jsxNamespaceReexports.tsx | 18 +++++++++++ 5 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/jsxNamespaceReexports.js create mode 100644 tests/baselines/reference/jsxNamespaceReexports.symbols create mode 100644 tests/baselines/reference/jsxNamespaceReexports.types create mode 100644 tests/cases/compiler/jsxNamespaceReexports.tsx diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index eadf654e3a2..9b59cb3574d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -18897,7 +18897,7 @@ namespace ts { const namespaceName = getJsxNamespace(location); const resolvedNamespace = resolveName(location, namespaceName, SymbolFlags.Namespace, /*diagnosticMessage*/ undefined, namespaceName, /*isUse*/ false); if (resolvedNamespace) { - const candidate = getSymbol(getExportsOfSymbol(resolveSymbol(resolvedNamespace)), JsxNames.JSX, SymbolFlags.Namespace); + const candidate = resolveSymbol(getSymbol(getExportsOfSymbol(resolveSymbol(resolvedNamespace)), JsxNames.JSX, SymbolFlags.Namespace)); if (candidate) { if (links) { links.jsxNamespace = candidate; diff --git a/tests/baselines/reference/jsxNamespaceReexports.js b/tests/baselines/reference/jsxNamespaceReexports.js new file mode 100644 index 00000000000..55c5ca4637e --- /dev/null +++ b/tests/baselines/reference/jsxNamespaceReexports.js @@ -0,0 +1,32 @@ +//// [tests/cases/compiler/jsxNamespaceReexports.tsx] //// + +//// [library.ts] +function createElement(element: string, props: any, ...children: any[]): any {} + +namespace JSX { + export interface IntrinsicElements { + [key: string]: Record; + } +} + +export { createElement, JSX }; +//// [index.tsx] +import * as MyLib from "./library"; + +const content = ; + +//// [library.js] +"use strict"; +exports.__esModule = true; +function createElement(element, props) { + var children = []; + for (var _i = 2; _i < arguments.length; _i++) { + children[_i - 2] = arguments[_i]; + } +} +exports.createElement = createElement; +//// [index.js] +"use strict"; +exports.__esModule = true; +var MyLib = require("./library"); +var content = MyLib.createElement("my-element", null); diff --git a/tests/baselines/reference/jsxNamespaceReexports.symbols b/tests/baselines/reference/jsxNamespaceReexports.symbols new file mode 100644 index 00000000000..c0a2c786d39 --- /dev/null +++ b/tests/baselines/reference/jsxNamespaceReexports.symbols @@ -0,0 +1,31 @@ +=== tests/cases/compiler/library.ts === +function createElement(element: string, props: any, ...children: any[]): any {} +>createElement : Symbol(createElement, Decl(library.ts, 0, 0)) +>element : Symbol(element, Decl(library.ts, 0, 23)) +>props : Symbol(props, Decl(library.ts, 0, 39)) +>children : Symbol(children, Decl(library.ts, 0, 51)) + +namespace JSX { +>JSX : Symbol(JSX, Decl(library.ts, 0, 79)) + + export interface IntrinsicElements { +>IntrinsicElements : Symbol(IntrinsicElements, Decl(library.ts, 2, 15)) + + [key: string]: Record; +>key : Symbol(key, Decl(library.ts, 4, 5)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) + } +} + +export { createElement, JSX }; +>createElement : Symbol(createElement, Decl(library.ts, 8, 8)) +>JSX : Symbol(JSX, Decl(library.ts, 8, 23)) + +=== tests/cases/compiler/index.tsx === +import * as MyLib from "./library"; +>MyLib : Symbol(MyLib, Decl(index.tsx, 0, 6)) + +const content = ; +>content : Symbol(content, Decl(index.tsx, 2, 5)) +>my-element : Symbol(MyLib.JSX.IntrinsicElements, Decl(library.ts, 2, 15)) + diff --git a/tests/baselines/reference/jsxNamespaceReexports.types b/tests/baselines/reference/jsxNamespaceReexports.types new file mode 100644 index 00000000000..857915efe39 --- /dev/null +++ b/tests/baselines/reference/jsxNamespaceReexports.types @@ -0,0 +1,27 @@ +=== tests/cases/compiler/library.ts === +function createElement(element: string, props: any, ...children: any[]): any {} +>createElement : (element: string, props: any, ...children: any[]) => any +>element : string +>props : any +>children : any[] + +namespace JSX { + export interface IntrinsicElements { + [key: string]: Record; +>key : string + } +} + +export { createElement, JSX }; +>createElement : (element: string, props: any, ...children: any[]) => any +>JSX : any + +=== tests/cases/compiler/index.tsx === +import * as MyLib from "./library"; +>MyLib : typeof MyLib + +const content = ; +>content : error +> : error +>my-element : any + diff --git a/tests/cases/compiler/jsxNamespaceReexports.tsx b/tests/cases/compiler/jsxNamespaceReexports.tsx new file mode 100644 index 00000000000..481fd7da2ca --- /dev/null +++ b/tests/cases/compiler/jsxNamespaceReexports.tsx @@ -0,0 +1,18 @@ + +// @jsx: react +// @jsxFactory: MyLib.createElement +// @strict: true +// @filename: library.ts +function createElement(element: string, props: any, ...children: any[]): any {} + +namespace JSX { + export interface IntrinsicElements { + [key: string]: Record; + } +} + +export { createElement, JSX }; +// @filename: index.tsx +import * as MyLib from "./library"; + +const content = ; \ No newline at end of file From 00bf32ca3967b07e8663d0cd2b3e2bbf572da88b Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Thu, 28 Feb 2019 14:35:03 -0800 Subject: [PATCH 18/19] Update LKG. --- lib/enu/diagnosticMessages.generated.json.lcg | 228 +- lib/lib.dom.d.ts | 872 ++- lib/lib.dom.iterable.d.ts | 7 + lib/lib.es2017.sharedmemory.d.ts | 4 +- lib/lib.es2018.asynciterable.d.ts | 44 + lib/lib.es2018.d.ts | 1 + lib/lib.es2019.array.d.ts | 223 + lib/lib.es2019.d.ts | 24 + lib/lib.es2019.full.d.ts | 25 + lib/lib.es2019.string.d.ts | 33 + lib/lib.es2019.symbol.d.ts | 26 + lib/lib.es5.d.ts | 102 +- lib/lib.esnext.d.ts | 5 +- lib/lib.webworker.d.ts | 184 +- lib/protocol.d.ts | 4 +- lib/tr/diagnosticMessages.generated.json | 2 +- lib/tsc.js | 4007 +++++++---- lib/tsserver.js | 5951 ++++++++++------ lib/tsserverlibrary.d.ts | 84 +- lib/tsserverlibrary.js | 6006 +++++++++++------ lib/typescript.d.ts | 59 +- lib/typescript.js | 5580 +++++++++------ lib/typescriptServices.d.ts | 59 +- lib/typescriptServices.js | 5579 +++++++++------ lib/typingsInstaller.js | 4518 ++++++++----- lib/zh-tw/diagnosticMessages.generated.json | 6 +- 26 files changed, 22528 insertions(+), 11105 deletions(-) create mode 100644 lib/lib.es2018.asynciterable.d.ts create mode 100644 lib/lib.es2019.array.d.ts create mode 100644 lib/lib.es2019.d.ts create mode 100644 lib/lib.es2019.full.d.ts create mode 100644 lib/lib.es2019.string.d.ts create mode 100644 lib/lib.es2019.symbol.d.ts diff --git a/lib/enu/diagnosticMessages.generated.json.lcg b/lib/enu/diagnosticMessages.generated.json.lcg index 61eb41991c4..17f927a74f3 100644 --- a/lib/enu/diagnosticMessages.generated.json.lcg +++ b/lib/enu/diagnosticMessages.generated.json.lcg @@ -27,6 +27,18 @@ + + + + + + + + + + + + @@ -129,6 +141,12 @@ + + + + + + @@ -849,12 +867,6 @@ - - - - - - @@ -1005,6 +1017,12 @@ + + + + + + @@ -1329,6 +1347,12 @@ + + + + + + @@ -1487,17 +1511,35 @@ - + - + + + + + + + + + + + + + - + + + + + + + @@ -1707,6 +1749,12 @@ + + + + + + @@ -2235,12 +2283,6 @@ - - - - - - @@ -2307,6 +2349,12 @@ + + + + + + @@ -2403,6 +2451,12 @@ + + + + + + @@ -2655,6 +2709,12 @@ + + + + + + @@ -3189,12 +3249,6 @@ - - - - - - @@ -3741,12 +3795,6 @@ - - - - - - @@ -3867,6 +3915,12 @@ + + + + + + @@ -4137,12 +4191,6 @@ - - - - - - @@ -4671,6 +4719,12 @@ + + + + + + @@ -4773,6 +4827,12 @@ + + + + + + @@ -5271,9 +5331,9 @@ - + - + @@ -5511,9 +5571,9 @@ - + - + @@ -5571,6 +5631,12 @@ + + + + + + @@ -5805,6 +5871,18 @@ + + + + + + + + + + + + @@ -5823,6 +5901,18 @@ + + + + + + + + + + + + @@ -5871,9 +5961,9 @@ - + - + @@ -5907,18 +5997,6 @@ - - - - - - - - - - - - @@ -5949,12 +6027,6 @@ - - - - - - @@ -6081,6 +6153,12 @@ + + + + + + @@ -6189,6 +6267,12 @@ + + + + + + @@ -6387,6 +6471,12 @@ + + + + + + @@ -6519,6 +6609,12 @@ + + + + + + @@ -6693,6 +6789,12 @@ + + + + + + @@ -6789,6 +6891,12 @@ + + + + + + @@ -6999,6 +7107,12 @@ + + + + + + diff --git a/lib/lib.dom.d.ts b/lib/lib.dom.d.ts index 464dea83926..7817a0e4267 100644 --- a/lib/lib.dom.d.ts +++ b/lib/lib.dom.d.ts @@ -203,6 +203,10 @@ interface ClientQueryOptions { type?: ClientTypes; } +interface ClipboardEventInit extends EventInit { + clipboardData?: DataTransfer | null; +} + interface CloseEventInit extends EventInit { code?: number; reason?: string; @@ -448,6 +452,10 @@ interface EventModifierInit extends UIEventInit { shiftKey?: boolean; } +interface EventSourceInit { + withCredentials?: boolean; +} + interface ExceptionInformation { domain?: string | null; } @@ -479,12 +487,16 @@ interface FocusOptions { preventScroll?: boolean; } +interface FullscreenOptions { + navigationUI?: FullscreenNavigationUI; +} + interface GainOptions extends AudioNodeOptions { gain?: number; } interface GamepadEventInit extends EventInit { - gamepad?: Gamepad; + gamepad: Gamepad; } interface GetNotificationOptions { @@ -619,15 +631,17 @@ interface MediaEncryptedEventInit extends EventInit { } interface MediaKeyMessageEventInit extends EventInit { - message?: ArrayBuffer | null; - messageType?: MediaKeyMessageType; + message: ArrayBuffer; + messageType: MediaKeyMessageType; } interface MediaKeySystemConfiguration { audioCapabilities?: MediaKeySystemMediaCapability[]; distinctiveIdentifier?: MediaKeysRequirement; initDataTypes?: string[]; + label?: string; persistentState?: MediaKeysRequirement; + sessionTypes?: string[]; videoCapabilities?: MediaKeySystemMediaCapability[]; } @@ -744,6 +758,8 @@ interface MouseEventInit extends EventModifierInit { buttons?: number; clientX?: number; clientY?: number; + movementX?: number; + movementY?: number; relatedTarget?: EventTarget | null; screenX?: number; screenY?: number; @@ -1462,6 +1478,11 @@ interface ServiceWorkerMessageEventInit extends EventInit { source?: ServiceWorker | MessagePort | null; } +interface ShadowRootInit { + delegatesFocus?: boolean; + mode: ShadowRootMode; +} + interface StereoPannerOptions extends AudioNodeOptions { pan?: number; } @@ -1629,6 +1650,7 @@ interface EventListener { (evt: Event): void; } +/** The ANGLE_instanced_arrays extension is part of the WebGL API and allows to draw the same object, or groups of similar objects multiple times, if they share the same vertex data, primitive count and type. */ interface ANGLE_instanced_arrays { drawArraysInstancedANGLE(mode: GLenum, first: GLint, count: GLsizei, primcount: GLsizei): void; drawElementsInstancedANGLE(mode: GLenum, count: GLsizei, type: GLenum, offset: GLintptr, primcount: GLsizei): void; @@ -1636,6 +1658,7 @@ interface ANGLE_instanced_arrays { readonly VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE: GLenum; } +/** The AbortController interface represents a controller object that allows you to abort one or more DOM requests as and when desired. */ interface AbortController { /** * Returns the AbortSignal object associated with this object. @@ -1654,16 +1677,17 @@ declare var AbortController: { }; interface AbortSignalEventMap { - "abort": ProgressEvent; + "abort": Event; } +/** The AbortSignal interface represents a signal object that allows you to communicate with a DOM request (such as a Fetch) and abort it if required via an AbortController object. */ interface AbortSignal extends EventTarget { /** * Returns true if this AbortSignal's AbortController has signaled to abort, and false * otherwise. */ readonly aborted: boolean; - onabort: ((this: AbortSignal, ev: ProgressEvent) => any) | null; + onabort: ((this: AbortSignal, ev: Event) => any) | null; addEventListener(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void; addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void; removeEventListener(type: K, listener: (this: AbortSignal, ev: AbortSignalEventMap[K]) => any, options?: boolean | EventListenerOptions): void; @@ -1708,6 +1732,7 @@ interface AesCmacParams extends Algorithm { length: number; } +/** The AnalyserNode interface represents a node able to provide real-time frequency and time-domain analysis information. It is an AudioNode that passes the audio stream unchanged from the input to the output, but allows you to take the generated data, process it, and create audio visualizations. */ interface AnalyserNode extends AudioNode { fftSize: number; readonly frequencyBinCount: number; @@ -1776,6 +1801,7 @@ declare var AnimationEffect: { new(): AnimationEffect; }; +/** The AnimationEvent interface represents events providing information related to animations. */ interface AnimationEvent extends Event { readonly animationName: string; readonly elapsedTime: number; @@ -1865,6 +1891,7 @@ declare var ApplicationCache: { readonly UPDATEREADY: number; }; +/** This type represents a DOM element's attribute as an object. In most DOM methods, you will probably directly retrieve the attribute as a string (e.g., Element.getAttribute(), but certain functions (e.g., Element.getAttributeNode()) or means of iterating give Attr types. */ interface Attr extends Node { readonly localName: string; readonly name: string; @@ -1880,6 +1907,7 @@ declare var Attr: { new(): Attr; }; +/** Objects of these types are designed to hold small audio snippets, typically less than 45 s. For longer sounds, objects implementing the MediaElementAudioSourceNode are more suitable. The buffer contains data in the following format:  non-interleaved IEEE754 32-bit linear PCM with a nominal range between -1 and +1, that is, 32bits floating point buffer, with each samples between -1.0 and 1.0. If the AudioBuffer has multiple channels, they are stored in separate buffer. */ interface AudioBuffer { readonly duration: number; readonly length: number; @@ -1895,6 +1923,7 @@ declare var AudioBuffer: { new(options: AudioBufferOptions): AudioBuffer; }; +/** The AudioBufferSourceNode interface is an AudioScheduledSourceNode which represents an audio source consisting of in-memory audio data, stored in an AudioBuffer. It's especially useful for playing back audio which has particularly stringent timing accuracy requirements, such as for sounds that must match a specific rhythm and can be kept in memory rather than being played from disk or the network. */ interface AudioBufferSourceNode extends AudioScheduledSourceNode { buffer: AudioBuffer | null; readonly detune: AudioParam; @@ -1914,6 +1943,7 @@ declare var AudioBufferSourceNode: { new(context: BaseAudioContext, options?: AudioBufferSourceOptions): AudioBufferSourceNode; }; +/** The AudioContext interface represents an audio-processing graph built from audio modules linked together, each represented by an AudioNode. */ interface AudioContext extends BaseAudioContext { readonly baseLatency: number; readonly outputLatency: number; @@ -1935,6 +1965,7 @@ declare var AudioContext: { new(contextOptions?: AudioContextOptions): AudioContext; }; +/** AudioDestinationNode has no output (as it is the output, no more AudioNode can be linked after it in the audio graph) and one input. The number of channels in the input must be between 0 and the maxChannelCount value or an exception is raised. */ interface AudioDestinationNode extends AudioNode { readonly maxChannelCount: number; } @@ -1944,6 +1975,7 @@ declare var AudioDestinationNode: { new(): AudioDestinationNode; }; +/** The AudioListener interface represents the position and orientation of the unique person listening to the audio scene, and is used in audio spatialization. All PannerNodes spatialize in relation to the AudioListener stored in the BaseAudioContext.listener attribute. */ interface AudioListener { readonly forwardX: AudioParam; readonly forwardY: AudioParam; @@ -1965,6 +1997,7 @@ declare var AudioListener: { new(): AudioListener; }; +/** The AudioNode interface is a generic interface for representing an audio processing module. Examples include: */ interface AudioNode extends EventTarget { channelCount: number; channelCountMode: ChannelCountMode; @@ -1988,6 +2021,7 @@ declare var AudioNode: { new(): AudioNode; }; +/** The Web Audio API's AudioParam interface represents an audio-related parameter, usually a parameter of an AudioNode (such as GainNode.gain). */ interface AudioParam { automationRate: AutomationRate; readonly defaultValue: number; @@ -2017,6 +2051,7 @@ declare var AudioParamMap: { new(): AudioParamMap; }; +/** The Web Audio API AudioProcessingEvent represents events that occur when a ScriptProcessorNode input buffer is ready to be processed. */ interface AudioProcessingEvent extends Event { readonly inputBuffer: AudioBuffer; readonly outputBuffer: AudioBuffer; @@ -2047,13 +2082,14 @@ declare var AudioScheduledSourceNode: { new(): AudioScheduledSourceNode; }; +/** The AudioTrack interface represents a single audio track from one of the HTML media elements,