Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use base constraint when testing whether a type needs an Awaited<T> wrapper #51230

Merged
merged 1 commit into from Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Expand Up @@ -36985,7 +36985,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;
}

Expand Down Expand Up @@ -37060,7 +37060,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;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/baselines/reference/asyncFunctionReturnType.2.js
@@ -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;
}
10 changes: 10 additions & 0 deletions tests/baselines/reference/asyncFunctionReturnType.2.symbols
@@ -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))
}
10 changes: 10 additions & 0 deletions tests/baselines/reference/asyncFunctionReturnType.2.types
@@ -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
}
6 changes: 6 additions & 0 deletions tests/cases/compiler/asyncFunctionReturnType.2.ts
@@ -0,0 +1,6 @@
// @target: esnext

// https://github.com/microsoft/TypeScript/issues/47291
class X {
f = async (): Promise<this> => this;
}