Skip to content

Commit a56b254

Browse files
authoredOct 21, 2022
Include 'this' type parameter in isRelatedTo fast path (#51230)
1 parent 3abd351 commit a56b254

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed
 

‎src/compiler/checker.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -36994,7 +36994,7 @@ namespace ts {
3699436994
}
3699536995

3699636996
// primitives with a `{ then() }` won't be unwrapped/adopted.
36997-
if (allTypesAssignableToKind(type, TypeFlags.Primitive | TypeFlags.Never)) {
36997+
if (allTypesAssignableToKind(getBaseConstraintOrType(type), TypeFlags.Primitive | TypeFlags.Never)) {
3699836998
return undefined;
3699936999
}
3700037000

@@ -37069,7 +37069,7 @@ namespace ts {
3706937069
* Determines whether a type is an object with a callable `then` member.
3707037070
*/
3707137071
function isThenableType(type: Type): boolean {
37072-
if (allTypesAssignableToKind(type, TypeFlags.Primitive | TypeFlags.Never)) {
37072+
if (allTypesAssignableToKind(getBaseConstraintOrType(type), TypeFlags.Primitive | TypeFlags.Never)) {
3707337073
// primitive types cannot be considered "thenable" since they are not objects.
3707437074
return false;
3707537075
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//// [asyncFunctionReturnType.2.ts]
2+
// https://github.com/microsoft/TypeScript/issues/47291
3+
class X {
4+
f = async (): Promise<this> => this;
5+
}
6+
7+
//// [asyncFunctionReturnType.2.js]
8+
// https://github.com/microsoft/TypeScript/issues/47291
9+
class X {
10+
f = async () => this;
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/compiler/asyncFunctionReturnType.2.ts ===
2+
// https://github.com/microsoft/TypeScript/issues/47291
3+
class X {
4+
>X : Symbol(X, Decl(asyncFunctionReturnType.2.ts, 0, 0))
5+
6+
f = async (): Promise<this> => this;
7+
>f : Symbol(X.f, Decl(asyncFunctionReturnType.2.ts, 1, 9))
8+
>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, --, --))
9+
>this : Symbol(X, Decl(asyncFunctionReturnType.2.ts, 0, 0))
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/compiler/asyncFunctionReturnType.2.ts ===
2+
// https://github.com/microsoft/TypeScript/issues/47291
3+
class X {
4+
>X : X
5+
6+
f = async (): Promise<this> => this;
7+
>f : () => Promise<this>
8+
>async (): Promise<this> => this : () => Promise<this>
9+
>this : this
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @target: esnext
2+
3+
// https://github.com/microsoft/TypeScript/issues/47291
4+
class X {
5+
f = async (): Promise<this> => this;
6+
}

0 commit comments

Comments
 (0)