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

Properly account for this argument in intersection apparent type caching #58677

Merged
merged 3 commits into from
May 31, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14565,7 +14565,11 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

function getApparentTypeOfIntersectionType(type: IntersectionType, thisArgument: Type) {
return type.resolvedApparentType || (type.resolvedApparentType = getTypeWithThisArgument(type, thisArgument, /*needApparentType*/ true));
if (type === thisArgument) {
return type.resolvedApparentType || (type.resolvedApparentType = getTypeWithThisArgument(type, thisArgument, /*needApparentType*/ true));
}
const key = `I${getTypeId(type)},${getTypeId(thisArgument)}`;
return getCachedType(key) ?? setCachedType(key, getTypeWithThisArgument(type, thisArgument, /*needApparentType*/ true));
}

function getResolvedTypeParameterDefault(typeParameter: TypeParameter): Type | undefined {
Expand Down
19 changes: 19 additions & 0 deletions tests/baselines/reference/intersectionApparentTypeCaching.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//// [tests/cases/compiler/intersectionApparentTypeCaching.ts] ////

=== intersectionApparentTypeCaching.ts ===
// https://github.com/microsoft/TypeScript/issues/58175

type TX<T extends any[] & object> = T["length"];
>TX : Symbol(TX, Decl(intersectionApparentTypeCaching.ts, 0, 0))
>T : Symbol(T, Decl(intersectionApparentTypeCaching.ts, 2, 8))
>T : Symbol(T, Decl(intersectionApparentTypeCaching.ts, 2, 8))

type T0<U extends any[] & object> = U;
>T0 : Symbol(T0, Decl(intersectionApparentTypeCaching.ts, 2, 48))
>U : Symbol(U, Decl(intersectionApparentTypeCaching.ts, 3, 8))
>U : Symbol(U, Decl(intersectionApparentTypeCaching.ts, 3, 8))

type T1 = T0<string[]>;
>T1 : Symbol(T1, Decl(intersectionApparentTypeCaching.ts, 3, 38))
>T0 : Symbol(T0, Decl(intersectionApparentTypeCaching.ts, 2, 48))

17 changes: 17 additions & 0 deletions tests/baselines/reference/intersectionApparentTypeCaching.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//// [tests/cases/compiler/intersectionApparentTypeCaching.ts] ////

=== intersectionApparentTypeCaching.ts ===
// https://github.com/microsoft/TypeScript/issues/58175

type TX<T extends any[] & object> = T["length"];
>TX : TX<T>
> : ^^^^^

type T0<U extends any[] & object> = U;
>T0 : U
> : ^

type T1 = T0<string[]>;
>T1 : string[]
> : ^^^^^^^^

8 changes: 8 additions & 0 deletions tests/cases/compiler/intersectionApparentTypeCaching.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @strict: true
// @noEmit: true

// https://github.com/microsoft/TypeScript/issues/58175

type TX<T extends any[] & object> = T["length"];
type T0<U extends any[] & object> = U;
type T1 = T0<string[]>;