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

This commit is contained in:
Anders Hejlsberg 2024-05-31 14:45:07 -07:00 коммит произвёл GitHub
Родитель 3aaa614bb9
Коммит 6c058d4ef6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
4 изменённых файлов: 49 добавлений и 1 удалений

Просмотреть файл

@ -14716,7 +14716,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 {

Просмотреть файл

@ -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))

Просмотреть файл

@ -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[]
> : ^^^^^^^^

Просмотреть файл

@ -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[]>;