Properly account for `this` argument in intersection apparent type caching (#58677)
This commit is contained in:
Родитель
3aaa614bb9
Коммит
6c058d4ef6
|
@ -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[]>;
|
Загрузка…
Ссылка в новой задаче