mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Include 'this' type parameter in isRelatedTo fast path (#51230)
This commit is contained in:
@@ -36994,7 +36994,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
// primitives with a `{ then() }` won't be unwrapped/adopted.
|
||||
if (allTypesAssignableToKind(type, TypeFlags.Primitive | TypeFlags.Never)) {
|
||||
if (allTypesAssignableToKind(getBaseConstraintOrType(type), TypeFlags.Primitive | TypeFlags.Never)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -37069,7 +37069,7 @@ namespace ts {
|
||||
* Determines whether a type is an object with a callable `then` member.
|
||||
*/
|
||||
function isThenableType(type: Type): boolean {
|
||||
if (allTypesAssignableToKind(type, TypeFlags.Primitive | TypeFlags.Never)) {
|
||||
if (allTypesAssignableToKind(getBaseConstraintOrType(type), TypeFlags.Primitive | TypeFlags.Never)) {
|
||||
// primitive types cannot be considered "thenable" since they are not objects.
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
//// [asyncFunctionReturnType.2.ts]
|
||||
// https://github.com/microsoft/TypeScript/issues/47291
|
||||
class X {
|
||||
f = async (): Promise<this> => this;
|
||||
}
|
||||
|
||||
//// [asyncFunctionReturnType.2.js]
|
||||
// https://github.com/microsoft/TypeScript/issues/47291
|
||||
class X {
|
||||
f = async () => this;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
=== tests/cases/compiler/asyncFunctionReturnType.2.ts ===
|
||||
// https://github.com/microsoft/TypeScript/issues/47291
|
||||
class X {
|
||||
>X : Symbol(X, Decl(asyncFunctionReturnType.2.ts, 0, 0))
|
||||
|
||||
f = async (): Promise<this> => this;
|
||||
>f : Symbol(X.f, Decl(asyncFunctionReturnType.2.ts, 1, 9))
|
||||
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
|
||||
>this : Symbol(X, Decl(asyncFunctionReturnType.2.ts, 0, 0))
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
=== tests/cases/compiler/asyncFunctionReturnType.2.ts ===
|
||||
// https://github.com/microsoft/TypeScript/issues/47291
|
||||
class X {
|
||||
>X : X
|
||||
|
||||
f = async (): Promise<this> => this;
|
||||
>f : () => Promise<this>
|
||||
>async (): Promise<this> => this : () => Promise<this>
|
||||
>this : this
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// @target: esnext
|
||||
|
||||
// https://github.com/microsoft/TypeScript/issues/47291
|
||||
class X {
|
||||
f = async (): Promise<this> => this;
|
||||
}
|
||||
Reference in New Issue
Block a user