From 0dc054cb12c4b54b6eabc577171eba8fc0616c56 Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Wed, 15 May 2024 12:53:39 -0700 Subject: [PATCH 1/3] return type if tryCreateAwaitedType fails --- src/compiler/checker.ts | 5 +- .../reference/awaitedTypeNoLib.errors.txt | 63 ++++++++++++++ tests/baselines/reference/awaitedTypeNoLib.js | 44 ++++++++++ .../reference/awaitedTypeNoLib.symbols | 85 +++++++++++++++++++ .../reference/awaitedTypeNoLib.types | 80 +++++++++++++++++ tests/cases/compiler/awaitedTypeNoLib.ts | 29 +++++++ 6 files changed, 302 insertions(+), 4 deletions(-) create mode 100644 tests/baselines/reference/awaitedTypeNoLib.errors.txt create mode 100644 tests/baselines/reference/awaitedTypeNoLib.js create mode 100644 tests/baselines/reference/awaitedTypeNoLib.symbols create mode 100644 tests/baselines/reference/awaitedTypeNoLib.types create mode 100644 tests/cases/compiler/awaitedTypeNoLib.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 51b3a8a6c509c..bd4fb160d3a57 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -41438,10 +41438,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // - The base constraint of `T` is an object type with a callable `then` method. if (isAwaitedTypeNeeded(type)) { - const awaitedType = tryCreateAwaitedType(type); - if (awaitedType) { - return awaitedType; - } + return tryCreateAwaitedType(type) ?? type; } Debug.assert(isAwaitedTypeInstantiation(type) || getPromisedTypeOfPromise(type) === undefined, "type provided should not be a non-generic 'promise'-like."); diff --git a/tests/baselines/reference/awaitedTypeNoLib.errors.txt b/tests/baselines/reference/awaitedTypeNoLib.errors.txt new file mode 100644 index 0000000000000..10d3fc693ee2f --- /dev/null +++ b/tests/baselines/reference/awaitedTypeNoLib.errors.txt @@ -0,0 +1,63 @@ +error TS2318: Cannot find global type 'Array'. +error TS2318: Cannot find global type 'Awaited'. +error TS2318: Cannot find global type 'Boolean'. +error TS2318: Cannot find global type 'Function'. +error TS2318: Cannot find global type 'IArguments'. +error TS2318: Cannot find global type 'Number'. +error TS2318: Cannot find global type 'Object'. +error TS2318: Cannot find global type 'RegExp'. +error TS2318: Cannot find global type 'String'. +awaitedTypeNoLib.ts(3,15): error TS2304: Cannot find name 'PromiseLike'. +awaitedTypeNoLib.ts(18,27): error TS2345: Argument of type 'NotPromise | Thennable>' is not assignable to parameter of type 'Thennable'. + Type 'NotPromise' is not assignable to type 'Thennable'. + Type 'TResult | (TResult extends PromiseLike ? never : TResult)' is not assignable to type 'Thennable'. + Type 'Thennable & TResult' is not assignable to type 'Thennable'. + Type 'unknown' is not assignable to type 'TResult'. + 'TResult' could be instantiated with an arbitrary type which could be unrelated to 'unknown'. + + +!!! error TS2318: Cannot find global type 'Array'. +!!! error TS2318: Cannot find global type 'Awaited'. +!!! error TS2318: Cannot find global type 'Boolean'. +!!! error TS2318: Cannot find global type 'Function'. +!!! error TS2318: Cannot find global type 'IArguments'. +!!! error TS2318: Cannot find global type 'Number'. +!!! error TS2318: Cannot find global type 'Object'. +!!! error TS2318: Cannot find global type 'RegExp'. +!!! error TS2318: Cannot find global type 'String'. +==== awaitedTypeNoLib.ts (2 errors) ==== + type NotPromise = T extends Thennable + ? T + : T extends PromiseLike + ~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'PromiseLike'. + ? never + : T; + + type Receiver = (value: NotPromise) => void; + + class Thennable { + then(a: Receiver) {} + + private handleResolve( + result: NotPromise | Thennable>, + resolve: Receiver, + ) { + if (result instanceof Thennable) { + // Error: Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. + this.resolvePromise(result, resolve); + ~~~~~~ +!!! error TS2345: Argument of type 'NotPromise | Thennable>' is not assignable to parameter of type 'Thennable'. +!!! error TS2345: Type 'NotPromise' is not assignable to type 'Thennable'. +!!! error TS2345: Type 'TResult | (TResult extends PromiseLike ? never : TResult)' is not assignable to type 'Thennable'. +!!! error TS2345: Type 'Thennable & TResult' is not assignable to type 'Thennable'. +!!! error TS2345: Type 'unknown' is not assignable to type 'TResult'. +!!! error TS2345: 'TResult' could be instantiated with an arbitrary type which could be unrelated to 'unknown'. + } + } + + private resolvePromise( + result: Thennable, + resolve: Receiver, + ) {} + } \ No newline at end of file diff --git a/tests/baselines/reference/awaitedTypeNoLib.js b/tests/baselines/reference/awaitedTypeNoLib.js new file mode 100644 index 0000000000000..d212e70702b4f --- /dev/null +++ b/tests/baselines/reference/awaitedTypeNoLib.js @@ -0,0 +1,44 @@ +//// [tests/cases/compiler/awaitedTypeNoLib.ts] //// + +//// [awaitedTypeNoLib.ts] +type NotPromise = T extends Thennable + ? T + : T extends PromiseLike + ? never + : T; + +type Receiver = (value: NotPromise) => void; + +class Thennable { + then(a: Receiver) {} + + private handleResolve( + result: NotPromise | Thennable>, + resolve: Receiver, + ) { + if (result instanceof Thennable) { + // Error: Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. + this.resolvePromise(result, resolve); + } + } + + private resolvePromise( + result: Thennable, + resolve: Receiver, + ) {} +} + +//// [awaitedTypeNoLib.js] +var Thennable = /** @class */ (function () { + function Thennable() { + } + Thennable.prototype.then = function (a) { }; + Thennable.prototype.handleResolve = function (result, resolve) { + if (result instanceof Thennable) { + // Error: Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. + this.resolvePromise(result, resolve); + } + }; + Thennable.prototype.resolvePromise = function (result, resolve) { }; + return Thennable; +}()); diff --git a/tests/baselines/reference/awaitedTypeNoLib.symbols b/tests/baselines/reference/awaitedTypeNoLib.symbols new file mode 100644 index 0000000000000..ea24bcc0ff021 --- /dev/null +++ b/tests/baselines/reference/awaitedTypeNoLib.symbols @@ -0,0 +1,85 @@ +//// [tests/cases/compiler/awaitedTypeNoLib.ts] //// + +=== awaitedTypeNoLib.ts === +type NotPromise = T extends Thennable +>NotPromise : Symbol(NotPromise, Decl(awaitedTypeNoLib.ts, 0, 0)) +>T : Symbol(T, Decl(awaitedTypeNoLib.ts, 0, 16)) +>T : Symbol(T, Decl(awaitedTypeNoLib.ts, 0, 16)) +>Thennable : Symbol(Thennable, Decl(awaitedTypeNoLib.ts, 6, 50)) + + ? T +>T : Symbol(T, Decl(awaitedTypeNoLib.ts, 0, 16)) + + : T extends PromiseLike +>T : Symbol(T, Decl(awaitedTypeNoLib.ts, 0, 16)) +>PromiseLike : Symbol(PromiseLike) + + ? never + : T; +>T : Symbol(T, Decl(awaitedTypeNoLib.ts, 0, 16)) + +type Receiver = (value: NotPromise) => void; +>Receiver : Symbol(Receiver, Decl(awaitedTypeNoLib.ts, 4, 6)) +>T : Symbol(T, Decl(awaitedTypeNoLib.ts, 6, 14)) +>value : Symbol(value, Decl(awaitedTypeNoLib.ts, 6, 20)) +>NotPromise : Symbol(NotPromise, Decl(awaitedTypeNoLib.ts, 0, 0)) +>T : Symbol(T, Decl(awaitedTypeNoLib.ts, 6, 14)) + +class Thennable { +>Thennable : Symbol(Thennable, Decl(awaitedTypeNoLib.ts, 6, 50)) +>T : Symbol(T, Decl(awaitedTypeNoLib.ts, 8, 16)) + + then(a: Receiver) {} +>then : Symbol(Thennable.then, Decl(awaitedTypeNoLib.ts, 8, 20)) +>a : Symbol(a, Decl(awaitedTypeNoLib.ts, 9, 7)) +>Receiver : Symbol(Receiver, Decl(awaitedTypeNoLib.ts, 4, 6)) +>T : Symbol(T, Decl(awaitedTypeNoLib.ts, 8, 16)) + + private handleResolve( +>handleResolve : Symbol(Thennable.handleResolve, Decl(awaitedTypeNoLib.ts, 9, 25)) +>TResult : Symbol(TResult, Decl(awaitedTypeNoLib.ts, 11, 24)) + + result: NotPromise | Thennable>, +>result : Symbol(result, Decl(awaitedTypeNoLib.ts, 11, 33)) +>NotPromise : Symbol(NotPromise, Decl(awaitedTypeNoLib.ts, 0, 0)) +>TResult : Symbol(TResult, Decl(awaitedTypeNoLib.ts, 11, 24)) +>Thennable : Symbol(Thennable, Decl(awaitedTypeNoLib.ts, 6, 50)) +>NotPromise : Symbol(NotPromise, Decl(awaitedTypeNoLib.ts, 0, 0)) +>TResult : Symbol(TResult, Decl(awaitedTypeNoLib.ts, 11, 24)) + + resolve: Receiver, +>resolve : Symbol(resolve, Decl(awaitedTypeNoLib.ts, 12, 65)) +>Receiver : Symbol(Receiver, Decl(awaitedTypeNoLib.ts, 4, 6)) +>TResult : Symbol(TResult, Decl(awaitedTypeNoLib.ts, 11, 24)) + + ) { + if (result instanceof Thennable) { +>result : Symbol(result, Decl(awaitedTypeNoLib.ts, 11, 33)) +>Thennable : Symbol(Thennable, Decl(awaitedTypeNoLib.ts, 6, 50)) + + // Error: Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. + this.resolvePromise(result, resolve); +>this.resolvePromise : Symbol(Thennable.resolvePromise, Decl(awaitedTypeNoLib.ts, 19, 3)) +>this : Symbol(Thennable, Decl(awaitedTypeNoLib.ts, 6, 50)) +>resolvePromise : Symbol(Thennable.resolvePromise, Decl(awaitedTypeNoLib.ts, 19, 3)) +>result : Symbol(result, Decl(awaitedTypeNoLib.ts, 11, 33)) +>resolve : Symbol(resolve, Decl(awaitedTypeNoLib.ts, 12, 65)) + } + } + + private resolvePromise( +>resolvePromise : Symbol(Thennable.resolvePromise, Decl(awaitedTypeNoLib.ts, 19, 3)) +>TResult : Symbol(TResult, Decl(awaitedTypeNoLib.ts, 21, 25)) + + result: Thennable, +>result : Symbol(result, Decl(awaitedTypeNoLib.ts, 21, 34)) +>Thennable : Symbol(Thennable, Decl(awaitedTypeNoLib.ts, 6, 50)) +>TResult : Symbol(TResult, Decl(awaitedTypeNoLib.ts, 21, 25)) + + resolve: Receiver, +>resolve : Symbol(resolve, Decl(awaitedTypeNoLib.ts, 22, 31)) +>Receiver : Symbol(Receiver, Decl(awaitedTypeNoLib.ts, 4, 6)) +>TResult : Symbol(TResult, Decl(awaitedTypeNoLib.ts, 21, 25)) + + ) {} +} diff --git a/tests/baselines/reference/awaitedTypeNoLib.types b/tests/baselines/reference/awaitedTypeNoLib.types new file mode 100644 index 0000000000000..532f16b4478f3 --- /dev/null +++ b/tests/baselines/reference/awaitedTypeNoLib.types @@ -0,0 +1,80 @@ +//// [tests/cases/compiler/awaitedTypeNoLib.ts] //// + +=== awaitedTypeNoLib.ts === +type NotPromise = T extends Thennable +>NotPromise : NotPromise +> : ^^^^^^^^^^^^^ + + ? T + : T extends PromiseLike + ? never + : T; + +type Receiver = (value: NotPromise) => void; +>Receiver : Receiver +> : ^^^^^^^^^^^ +>value : NotPromise +> : ^^^^^^^^^^^^^ + +class Thennable { +>Thennable : Thennable +> : ^^^^^^^^^^^^ + + then(a: Receiver) {} +>then : (a: Receiver) => void +> : ^ ^^ ^^^^^^^^^ +>a : Receiver +> : ^^^^^^^^^^^ + + private handleResolve( +>handleResolve : (result: NotPromise | Thennable>, resolve: Receiver) => void +> : ^ ^^ ^^ ^^ ^^ ^^^^^^^^^ + + result: NotPromise | Thennable>, +>result : NotPromise | Thennable> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + resolve: Receiver, +>resolve : Receiver +> : ^^^^^^^^^^^^^^^^^ + + ) { + if (result instanceof Thennable) { +>result instanceof Thennable : boolean +> : ^^^^^^^ +>result : NotPromise | Thennable> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>Thennable : typeof Thennable +> : ^^^^^^^^^^^^^^^^ + + // Error: Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. + this.resolvePromise(result, resolve); +>this.resolvePromise(result, resolve) : void +> : ^^^^ +>this.resolvePromise : (result: Thennable, resolve: Receiver) => void +> : ^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>this : this +> : ^^^^ +>resolvePromise : (result: Thennable, resolve: Receiver) => void +> : ^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>result : NotPromise | Thennable> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>resolve : Receiver +> : ^^^^^^^^^^^^^^^^^ + } + } + + private resolvePromise( +>resolvePromise : (result: Thennable, resolve: Receiver) => void +> : ^ ^^ ^^ ^^ ^^ ^^^^^^^^^ + + result: Thennable, +>result : Thennable +> : ^^^^^^^^^^^^^^^^^^ + + resolve: Receiver, +>resolve : Receiver +> : ^^^^^^^^^^^^^^^^^ + + ) {} +} diff --git a/tests/cases/compiler/awaitedTypeNoLib.ts b/tests/cases/compiler/awaitedTypeNoLib.ts new file mode 100644 index 0000000000000..2572a6181bd84 --- /dev/null +++ b/tests/cases/compiler/awaitedTypeNoLib.ts @@ -0,0 +1,29 @@ +// @strictFunctionTypes: true +// @noLib: true + +type NotPromise = T extends Thennable + ? T + : T extends PromiseLike + ? never + : T; + +type Receiver = (value: NotPromise) => void; + +class Thennable { + then(a: Receiver) {} + + private handleResolve( + result: NotPromise | Thennable>, + resolve: Receiver, + ) { + if (result instanceof Thennable) { + // Error: Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. + this.resolvePromise(result, resolve); + } + } + + private resolvePromise( + result: Thennable, + resolve: Receiver, + ) {} +} \ No newline at end of file From 7e89f2fccd008e5e2638c3bbe5c8020c12cd07c7 Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Wed, 15 May 2024 13:07:09 -0700 Subject: [PATCH 2/3] update comment --- tests/baselines/reference/awaitedTypeNoLib.errors.txt | 2 +- tests/baselines/reference/awaitedTypeNoLib.js | 4 ++-- tests/baselines/reference/awaitedTypeNoLib.symbols | 2 +- tests/baselines/reference/awaitedTypeNoLib.types | 2 +- tests/cases/compiler/awaitedTypeNoLib.ts | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/baselines/reference/awaitedTypeNoLib.errors.txt b/tests/baselines/reference/awaitedTypeNoLib.errors.txt index 10d3fc693ee2f..fc869a120bf8b 100644 --- a/tests/baselines/reference/awaitedTypeNoLib.errors.txt +++ b/tests/baselines/reference/awaitedTypeNoLib.errors.txt @@ -44,7 +44,7 @@ awaitedTypeNoLib.ts(18,27): error TS2345: Argument of type 'NotPromise resolve: Receiver, ) { if (result instanceof Thennable) { - // Error: Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. + // #58547 This previously was a Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. this.resolvePromise(result, resolve); ~~~~~~ !!! error TS2345: Argument of type 'NotPromise | Thennable>' is not assignable to parameter of type 'Thennable'. diff --git a/tests/baselines/reference/awaitedTypeNoLib.js b/tests/baselines/reference/awaitedTypeNoLib.js index d212e70702b4f..4710340f85197 100644 --- a/tests/baselines/reference/awaitedTypeNoLib.js +++ b/tests/baselines/reference/awaitedTypeNoLib.js @@ -17,7 +17,7 @@ class Thennable { resolve: Receiver, ) { if (result instanceof Thennable) { - // Error: Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. + // #58547 This previously was a Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. this.resolvePromise(result, resolve); } } @@ -35,7 +35,7 @@ var Thennable = /** @class */ (function () { Thennable.prototype.then = function (a) { }; Thennable.prototype.handleResolve = function (result, resolve) { if (result instanceof Thennable) { - // Error: Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. + // #58547 This previously was a Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. this.resolvePromise(result, resolve); } }; diff --git a/tests/baselines/reference/awaitedTypeNoLib.symbols b/tests/baselines/reference/awaitedTypeNoLib.symbols index ea24bcc0ff021..a7dcd6a2b80c9 100644 --- a/tests/baselines/reference/awaitedTypeNoLib.symbols +++ b/tests/baselines/reference/awaitedTypeNoLib.symbols @@ -57,7 +57,7 @@ class Thennable { >result : Symbol(result, Decl(awaitedTypeNoLib.ts, 11, 33)) >Thennable : Symbol(Thennable, Decl(awaitedTypeNoLib.ts, 6, 50)) - // Error: Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. + // #58547 This previously was a Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. this.resolvePromise(result, resolve); >this.resolvePromise : Symbol(Thennable.resolvePromise, Decl(awaitedTypeNoLib.ts, 19, 3)) >this : Symbol(Thennable, Decl(awaitedTypeNoLib.ts, 6, 50)) diff --git a/tests/baselines/reference/awaitedTypeNoLib.types b/tests/baselines/reference/awaitedTypeNoLib.types index 532f16b4478f3..58db37f04eaa1 100644 --- a/tests/baselines/reference/awaitedTypeNoLib.types +++ b/tests/baselines/reference/awaitedTypeNoLib.types @@ -47,7 +47,7 @@ class Thennable { >Thennable : typeof Thennable > : ^^^^^^^^^^^^^^^^ - // Error: Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. + // #58547 This previously was a Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. this.resolvePromise(result, resolve); >this.resolvePromise(result, resolve) : void > : ^^^^ diff --git a/tests/cases/compiler/awaitedTypeNoLib.ts b/tests/cases/compiler/awaitedTypeNoLib.ts index 2572a6181bd84..cf94114d71c6c 100644 --- a/tests/cases/compiler/awaitedTypeNoLib.ts +++ b/tests/cases/compiler/awaitedTypeNoLib.ts @@ -17,7 +17,7 @@ class Thennable { resolve: Receiver, ) { if (result instanceof Thennable) { - // Error: Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. + // #58547 This previously was a Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. this.resolvePromise(result, resolve); } } From 43762421733e18acf1b633cb4262aaa59b89ad1c Mon Sep 17 00:00:00 2001 From: Isabel Duan Date: Wed, 15 May 2024 13:17:12 -0700 Subject: [PATCH 3/3] rename thennable -> thenable --- .../reference/awaitedTypeNoLib.errors.txt | 26 ++++----- tests/baselines/reference/awaitedTypeNoLib.js | 24 ++++----- .../reference/awaitedTypeNoLib.symbols | 42 +++++++-------- .../reference/awaitedTypeNoLib.types | 54 +++++++++---------- tests/cases/compiler/awaitedTypeNoLib.ts | 10 ++-- 5 files changed, 78 insertions(+), 78 deletions(-) diff --git a/tests/baselines/reference/awaitedTypeNoLib.errors.txt b/tests/baselines/reference/awaitedTypeNoLib.errors.txt index fc869a120bf8b..f19971eed35b7 100644 --- a/tests/baselines/reference/awaitedTypeNoLib.errors.txt +++ b/tests/baselines/reference/awaitedTypeNoLib.errors.txt @@ -8,10 +8,10 @@ error TS2318: Cannot find global type 'Object'. error TS2318: Cannot find global type 'RegExp'. error TS2318: Cannot find global type 'String'. awaitedTypeNoLib.ts(3,15): error TS2304: Cannot find name 'PromiseLike'. -awaitedTypeNoLib.ts(18,27): error TS2345: Argument of type 'NotPromise | Thennable>' is not assignable to parameter of type 'Thennable'. - Type 'NotPromise' is not assignable to type 'Thennable'. - Type 'TResult | (TResult extends PromiseLike ? never : TResult)' is not assignable to type 'Thennable'. - Type 'Thennable & TResult' is not assignable to type 'Thennable'. +awaitedTypeNoLib.ts(18,27): error TS2345: Argument of type 'NotPromise | Thenable>' is not assignable to parameter of type 'Thenable'. + Type 'NotPromise' is not assignable to type 'Thenable'. + Type 'TResult | (TResult extends PromiseLike ? never : TResult)' is not assignable to type 'Thenable'. + Type 'Thenable & TResult' is not assignable to type 'Thenable'. Type 'unknown' is not assignable to type 'TResult'. 'TResult' could be instantiated with an arbitrary type which could be unrelated to 'unknown'. @@ -26,7 +26,7 @@ awaitedTypeNoLib.ts(18,27): error TS2345: Argument of type 'NotPromise !!! error TS2318: Cannot find global type 'RegExp'. !!! error TS2318: Cannot find global type 'String'. ==== awaitedTypeNoLib.ts (2 errors) ==== - type NotPromise = T extends Thennable + type NotPromise = T extends Thenable ? T : T extends PromiseLike ~~~~~~~~~~~ @@ -36,28 +36,28 @@ awaitedTypeNoLib.ts(18,27): error TS2345: Argument of type 'NotPromise type Receiver = (value: NotPromise) => void; - class Thennable { + class Thenable { then(a: Receiver) {} private handleResolve( - result: NotPromise | Thennable>, + result: NotPromise | Thenable>, resolve: Receiver, ) { - if (result instanceof Thennable) { + if (result instanceof Thenable) { // #58547 This previously was a Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. this.resolvePromise(result, resolve); ~~~~~~ -!!! error TS2345: Argument of type 'NotPromise | Thennable>' is not assignable to parameter of type 'Thennable'. -!!! error TS2345: Type 'NotPromise' is not assignable to type 'Thennable'. -!!! error TS2345: Type 'TResult | (TResult extends PromiseLike ? never : TResult)' is not assignable to type 'Thennable'. -!!! error TS2345: Type 'Thennable & TResult' is not assignable to type 'Thennable'. +!!! error TS2345: Argument of type 'NotPromise | Thenable>' is not assignable to parameter of type 'Thenable'. +!!! error TS2345: Type 'NotPromise' is not assignable to type 'Thenable'. +!!! error TS2345: Type 'TResult | (TResult extends PromiseLike ? never : TResult)' is not assignable to type 'Thenable'. +!!! error TS2345: Type 'Thenable & TResult' is not assignable to type 'Thenable'. !!! error TS2345: Type 'unknown' is not assignable to type 'TResult'. !!! error TS2345: 'TResult' could be instantiated with an arbitrary type which could be unrelated to 'unknown'. } } private resolvePromise( - result: Thennable, + result: Thenable, resolve: Receiver, ) {} } \ No newline at end of file diff --git a/tests/baselines/reference/awaitedTypeNoLib.js b/tests/baselines/reference/awaitedTypeNoLib.js index 4710340f85197..6a80032cd56da 100644 --- a/tests/baselines/reference/awaitedTypeNoLib.js +++ b/tests/baselines/reference/awaitedTypeNoLib.js @@ -1,7 +1,7 @@ //// [tests/cases/compiler/awaitedTypeNoLib.ts] //// //// [awaitedTypeNoLib.ts] -type NotPromise = T extends Thennable +type NotPromise = T extends Thenable ? T : T extends PromiseLike ? never @@ -9,36 +9,36 @@ type NotPromise = T extends Thennable type Receiver = (value: NotPromise) => void; -class Thennable { +class Thenable { then(a: Receiver) {} private handleResolve( - result: NotPromise | Thennable>, + result: NotPromise | Thenable>, resolve: Receiver, ) { - if (result instanceof Thennable) { + if (result instanceof Thenable) { // #58547 This previously was a Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. this.resolvePromise(result, resolve); } } private resolvePromise( - result: Thennable, + result: Thenable, resolve: Receiver, ) {} } //// [awaitedTypeNoLib.js] -var Thennable = /** @class */ (function () { - function Thennable() { +var Thenable = /** @class */ (function () { + function Thenable() { } - Thennable.prototype.then = function (a) { }; - Thennable.prototype.handleResolve = function (result, resolve) { - if (result instanceof Thennable) { + Thenable.prototype.then = function (a) { }; + Thenable.prototype.handleResolve = function (result, resolve) { + if (result instanceof Thenable) { // #58547 This previously was a Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. this.resolvePromise(result, resolve); } }; - Thennable.prototype.resolvePromise = function (result, resolve) { }; - return Thennable; + Thenable.prototype.resolvePromise = function (result, resolve) { }; + return Thenable; }()); diff --git a/tests/baselines/reference/awaitedTypeNoLib.symbols b/tests/baselines/reference/awaitedTypeNoLib.symbols index a7dcd6a2b80c9..04f7f9d70a277 100644 --- a/tests/baselines/reference/awaitedTypeNoLib.symbols +++ b/tests/baselines/reference/awaitedTypeNoLib.symbols @@ -1,11 +1,11 @@ //// [tests/cases/compiler/awaitedTypeNoLib.ts] //// === awaitedTypeNoLib.ts === -type NotPromise = T extends Thennable +type NotPromise = T extends Thenable >NotPromise : Symbol(NotPromise, Decl(awaitedTypeNoLib.ts, 0, 0)) >T : Symbol(T, Decl(awaitedTypeNoLib.ts, 0, 16)) >T : Symbol(T, Decl(awaitedTypeNoLib.ts, 0, 16)) ->Thennable : Symbol(Thennable, Decl(awaitedTypeNoLib.ts, 6, 50)) +>Thenable : Symbol(Thenable, Decl(awaitedTypeNoLib.ts, 6, 50)) ? T >T : Symbol(T, Decl(awaitedTypeNoLib.ts, 0, 16)) @@ -25,59 +25,59 @@ type Receiver = (value: NotPromise) => void; >NotPromise : Symbol(NotPromise, Decl(awaitedTypeNoLib.ts, 0, 0)) >T : Symbol(T, Decl(awaitedTypeNoLib.ts, 6, 14)) -class Thennable { ->Thennable : Symbol(Thennable, Decl(awaitedTypeNoLib.ts, 6, 50)) ->T : Symbol(T, Decl(awaitedTypeNoLib.ts, 8, 16)) +class Thenable { +>Thenable : Symbol(Thenable, Decl(awaitedTypeNoLib.ts, 6, 50)) +>T : Symbol(T, Decl(awaitedTypeNoLib.ts, 8, 15)) then(a: Receiver) {} ->then : Symbol(Thennable.then, Decl(awaitedTypeNoLib.ts, 8, 20)) +>then : Symbol(Thenable.then, Decl(awaitedTypeNoLib.ts, 8, 19)) >a : Symbol(a, Decl(awaitedTypeNoLib.ts, 9, 7)) >Receiver : Symbol(Receiver, Decl(awaitedTypeNoLib.ts, 4, 6)) ->T : Symbol(T, Decl(awaitedTypeNoLib.ts, 8, 16)) +>T : Symbol(T, Decl(awaitedTypeNoLib.ts, 8, 15)) private handleResolve( ->handleResolve : Symbol(Thennable.handleResolve, Decl(awaitedTypeNoLib.ts, 9, 25)) +>handleResolve : Symbol(Thenable.handleResolve, Decl(awaitedTypeNoLib.ts, 9, 25)) >TResult : Symbol(TResult, Decl(awaitedTypeNoLib.ts, 11, 24)) - result: NotPromise | Thennable>, + result: NotPromise | Thenable>, >result : Symbol(result, Decl(awaitedTypeNoLib.ts, 11, 33)) >NotPromise : Symbol(NotPromise, Decl(awaitedTypeNoLib.ts, 0, 0)) >TResult : Symbol(TResult, Decl(awaitedTypeNoLib.ts, 11, 24)) ->Thennable : Symbol(Thennable, Decl(awaitedTypeNoLib.ts, 6, 50)) +>Thenable : Symbol(Thenable, Decl(awaitedTypeNoLib.ts, 6, 50)) >NotPromise : Symbol(NotPromise, Decl(awaitedTypeNoLib.ts, 0, 0)) >TResult : Symbol(TResult, Decl(awaitedTypeNoLib.ts, 11, 24)) resolve: Receiver, ->resolve : Symbol(resolve, Decl(awaitedTypeNoLib.ts, 12, 65)) +>resolve : Symbol(resolve, Decl(awaitedTypeNoLib.ts, 12, 64)) >Receiver : Symbol(Receiver, Decl(awaitedTypeNoLib.ts, 4, 6)) >TResult : Symbol(TResult, Decl(awaitedTypeNoLib.ts, 11, 24)) ) { - if (result instanceof Thennable) { + if (result instanceof Thenable) { >result : Symbol(result, Decl(awaitedTypeNoLib.ts, 11, 33)) ->Thennable : Symbol(Thennable, Decl(awaitedTypeNoLib.ts, 6, 50)) +>Thenable : Symbol(Thenable, Decl(awaitedTypeNoLib.ts, 6, 50)) // #58547 This previously was a Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. this.resolvePromise(result, resolve); ->this.resolvePromise : Symbol(Thennable.resolvePromise, Decl(awaitedTypeNoLib.ts, 19, 3)) ->this : Symbol(Thennable, Decl(awaitedTypeNoLib.ts, 6, 50)) ->resolvePromise : Symbol(Thennable.resolvePromise, Decl(awaitedTypeNoLib.ts, 19, 3)) +>this.resolvePromise : Symbol(Thenable.resolvePromise, Decl(awaitedTypeNoLib.ts, 19, 3)) +>this : Symbol(Thenable, Decl(awaitedTypeNoLib.ts, 6, 50)) +>resolvePromise : Symbol(Thenable.resolvePromise, Decl(awaitedTypeNoLib.ts, 19, 3)) >result : Symbol(result, Decl(awaitedTypeNoLib.ts, 11, 33)) ->resolve : Symbol(resolve, Decl(awaitedTypeNoLib.ts, 12, 65)) +>resolve : Symbol(resolve, Decl(awaitedTypeNoLib.ts, 12, 64)) } } private resolvePromise( ->resolvePromise : Symbol(Thennable.resolvePromise, Decl(awaitedTypeNoLib.ts, 19, 3)) +>resolvePromise : Symbol(Thenable.resolvePromise, Decl(awaitedTypeNoLib.ts, 19, 3)) >TResult : Symbol(TResult, Decl(awaitedTypeNoLib.ts, 21, 25)) - result: Thennable, + result: Thenable, >result : Symbol(result, Decl(awaitedTypeNoLib.ts, 21, 34)) ->Thennable : Symbol(Thennable, Decl(awaitedTypeNoLib.ts, 6, 50)) +>Thenable : Symbol(Thenable, Decl(awaitedTypeNoLib.ts, 6, 50)) >TResult : Symbol(TResult, Decl(awaitedTypeNoLib.ts, 21, 25)) resolve: Receiver, ->resolve : Symbol(resolve, Decl(awaitedTypeNoLib.ts, 22, 31)) +>resolve : Symbol(resolve, Decl(awaitedTypeNoLib.ts, 22, 30)) >Receiver : Symbol(Receiver, Decl(awaitedTypeNoLib.ts, 4, 6)) >TResult : Symbol(TResult, Decl(awaitedTypeNoLib.ts, 21, 25)) diff --git a/tests/baselines/reference/awaitedTypeNoLib.types b/tests/baselines/reference/awaitedTypeNoLib.types index 58db37f04eaa1..f9fd4ea0a4f0a 100644 --- a/tests/baselines/reference/awaitedTypeNoLib.types +++ b/tests/baselines/reference/awaitedTypeNoLib.types @@ -1,7 +1,7 @@ //// [tests/cases/compiler/awaitedTypeNoLib.ts] //// === awaitedTypeNoLib.ts === -type NotPromise = T extends Thennable +type NotPromise = T extends Thenable >NotPromise : NotPromise > : ^^^^^^^^^^^^^ @@ -16,9 +16,9 @@ type Receiver = (value: NotPromise) => void; >value : NotPromise > : ^^^^^^^^^^^^^ -class Thennable { ->Thennable : Thennable -> : ^^^^^^^^^^^^ +class Thenable { +>Thenable : Thenable +> : ^^^^^^^^^^^ then(a: Receiver) {} >then : (a: Receiver) => void @@ -27,50 +27,50 @@ class Thennable { > : ^^^^^^^^^^^ private handleResolve( ->handleResolve : (result: NotPromise | Thennable>, resolve: Receiver) => void -> : ^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>handleResolve : (result: NotPromise | Thenable>, resolve: Receiver) => void +> : ^ ^^ ^^ ^^ ^^ ^^^^^^^^^ - result: NotPromise | Thennable>, ->result : NotPromise | Thennable> -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + result: NotPromise | Thenable>, +>result : NotPromise | Thenable> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ resolve: Receiver, >resolve : Receiver > : ^^^^^^^^^^^^^^^^^ ) { - if (result instanceof Thennable) { ->result instanceof Thennable : boolean -> : ^^^^^^^ ->result : NotPromise | Thennable> -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->Thennable : typeof Thennable -> : ^^^^^^^^^^^^^^^^ + if (result instanceof Thenable) { +>result instanceof Thenable : boolean +> : ^^^^^^^ +>result : NotPromise | Thenable> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>Thenable : typeof Thenable +> : ^^^^^^^^^^^^^^^ // #58547 This previously was a Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. this.resolvePromise(result, resolve); >this.resolvePromise(result, resolve) : void > : ^^^^ ->this.resolvePromise : (result: Thennable, resolve: Receiver) => void -> : ^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>this.resolvePromise : (result: Thenable, resolve: Receiver) => void +> : ^ ^^ ^^ ^^ ^^ ^^^^^^^^^ >this : this > : ^^^^ ->resolvePromise : (result: Thennable, resolve: Receiver) => void -> : ^ ^^ ^^ ^^ ^^ ^^^^^^^^^ ->result : NotPromise | Thennable> -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>resolvePromise : (result: Thenable, resolve: Receiver) => void +> : ^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>result : NotPromise | Thenable> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >resolve : Receiver > : ^^^^^^^^^^^^^^^^^ } } private resolvePromise( ->resolvePromise : (result: Thennable, resolve: Receiver) => void -> : ^ ^^ ^^ ^^ ^^ ^^^^^^^^^ +>resolvePromise : (result: Thenable, resolve: Receiver) => void +> : ^ ^^ ^^ ^^ ^^ ^^^^^^^^^ - result: Thennable, ->result : Thennable -> : ^^^^^^^^^^^^^^^^^^ + result: Thenable, +>result : Thenable +> : ^^^^^^^^^^^^^^^^^ resolve: Receiver, >resolve : Receiver diff --git a/tests/cases/compiler/awaitedTypeNoLib.ts b/tests/cases/compiler/awaitedTypeNoLib.ts index cf94114d71c6c..5211f05016307 100644 --- a/tests/cases/compiler/awaitedTypeNoLib.ts +++ b/tests/cases/compiler/awaitedTypeNoLib.ts @@ -1,7 +1,7 @@ // @strictFunctionTypes: true // @noLib: true -type NotPromise = T extends Thennable +type NotPromise = T extends Thenable ? T : T extends PromiseLike ? never @@ -9,21 +9,21 @@ type NotPromise = T extends Thennable type Receiver = (value: NotPromise) => void; -class Thennable { +class Thenable { then(a: Receiver) {} private handleResolve( - result: NotPromise | Thennable>, + result: NotPromise | Thenable>, resolve: Receiver, ) { - if (result instanceof Thennable) { + if (result instanceof Thenable) { // #58547 This previously was a Debug Failure. False expression: type provided should not be a non-generic 'promise'-like. this.resolvePromise(result, resolve); } } private resolvePromise( - result: Thennable, + result: Thenable, resolve: Receiver, ) {} } \ No newline at end of file