Skip to content

Commit 4a34f45

Browse files
authored
Revert "Fixed apparent type of homomorphic mapped type with non-homomorphic instantiation (#56727)" and add test (#57092)
1 parent 140fa7e commit 4a34f45

7 files changed

+61
-252
lines changed

src/compiler/checker.ts

+5-23
Original file line numberDiff line numberDiff line change
@@ -2053,7 +2053,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
20532053
var noConstraintType = createAnonymousType(/*symbol*/ undefined, emptySymbols, emptyArray, emptyArray, emptyArray);
20542054
var circularConstraintType = createAnonymousType(/*symbol*/ undefined, emptySymbols, emptyArray, emptyArray, emptyArray);
20552055
var resolvingDefaultType = createAnonymousType(/*symbol*/ undefined, emptySymbols, emptyArray, emptyArray, emptyArray);
2056-
var resolvingApparentMappedType = createAnonymousType(/*symbol*/ undefined, emptySymbols, emptyArray, emptyArray, emptyArray);
20572056

20582057
var markerSuperType = createTypeParameter();
20592058
var markerSubType = createTypeParameter();
@@ -14539,32 +14538,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1453914538
}
1454014539

1454114540
function getApparentTypeOfMappedType(type: MappedType) {
14542-
if (type.resolvedApparentType) {
14543-
if (type.resolvedApparentType === resolvingApparentMappedType) {
14544-
return type.resolvedApparentType = type;
14545-
}
14546-
return type.resolvedApparentType;
14547-
}
14548-
type.resolvedApparentType = resolvingApparentMappedType;
14549-
return type.resolvedApparentType = getResolvedApparentTypeOfMappedType(type);
14541+
return type.resolvedApparentType || (type.resolvedApparentType = getResolvedApparentTypeOfMappedType(type));
1455014542
}
1455114543

1455214544
function getResolvedApparentTypeOfMappedType(type: MappedType) {
14553-
const mappedType = type.target as MappedType || type;
14554-
const typeVariable = getHomomorphicTypeVariable(mappedType);
14555-
if (typeVariable && !mappedType.declaration.nameType) {
14556-
let constraint: Type | undefined;
14557-
if (!type.target) {
14558-
constraint = getConstraintOfTypeParameter(typeVariable);
14559-
}
14560-
else {
14561-
const modifiersConstraint = getConstraintOfType(getModifiersTypeFromMappedType(type));
14562-
if (modifiersConstraint) {
14563-
constraint = getApparentType(modifiersConstraint);
14564-
}
14565-
}
14545+
const typeVariable = getHomomorphicTypeVariable(type);
14546+
if (typeVariable && !type.declaration.nameType) {
14547+
const constraint = getConstraintOfTypeParameter(typeVariable);
1456614548
if (constraint && everyType(constraint, isArrayOrTupleType)) {
14567-
return instantiateType(mappedType, prependTypeMapping(typeVariable, constraint, mappedType.mapper));
14549+
return instantiateType(type, prependTypeMapping(typeVariable, constraint, type.mapper));
1456814550
}
1456914551
}
1457014552
return type;

tests/baselines/reference/homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.symbols

-92
This file was deleted.

tests/baselines/reference/homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.types

-95
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//// [tests/cases/compiler/nestedHomomorphicMappedTypesWithArrayConstraint1.ts] ////
2+
3+
=== nestedHomomorphicMappedTypesWithArrayConstraint1.ts ===
4+
// Based on @types/sinon v10
5+
6+
type MatchArguments<T> = {
7+
>MatchArguments : Symbol(MatchArguments, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 0, 0))
8+
>T : Symbol(T, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 2, 20))
9+
10+
[K in keyof T]: T[K];
11+
>K : Symbol(K, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 3, 5))
12+
>T : Symbol(T, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 2, 20))
13+
>T : Symbol(T, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 2, 20))
14+
>K : Symbol(K, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 3, 5))
15+
16+
};
17+
18+
interface SinonSpyCallApi<TArgs extends any[] = any[]> {
19+
>SinonSpyCallApi : Symbol(SinonSpyCallApi, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 4, 2))
20+
>TArgs : Symbol(TArgs, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 6, 26))
21+
22+
calledWith(...args: Partial<MatchArguments<TArgs>>): boolean;
23+
>calledWith : Symbol(SinonSpyCallApi.calledWith, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 6, 56))
24+
>args : Symbol(args, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 7, 15))
25+
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --))
26+
>MatchArguments : Symbol(MatchArguments, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 0, 0))
27+
>TArgs : Symbol(TArgs, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 6, 26))
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [tests/cases/compiler/nestedHomomorphicMappedTypesWithArrayConstraint1.ts] ////
2+
3+
=== nestedHomomorphicMappedTypesWithArrayConstraint1.ts ===
4+
// Based on @types/sinon v10
5+
6+
type MatchArguments<T> = {
7+
>MatchArguments : MatchArguments<T>
8+
9+
[K in keyof T]: T[K];
10+
};
11+
12+
interface SinonSpyCallApi<TArgs extends any[] = any[]> {
13+
calledWith(...args: Partial<MatchArguments<TArgs>>): boolean;
14+
>calledWith : (...args: Partial<MatchArguments<TArgs>>) => boolean
15+
>args : Partial<MatchArguments<TArgs>>
16+
}

tests/cases/compiler/homomorphicMappedTypeWithNonHomomorphicInstantiationSpreadable1.ts

-42
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @strict: true
2+
// @noEmit: true
3+
4+
// Based on @types/sinon v10
5+
6+
type MatchArguments<T> = {
7+
[K in keyof T]: T[K];
8+
};
9+
10+
interface SinonSpyCallApi<TArgs extends any[] = any[]> {
11+
calledWith(...args: Partial<MatchArguments<TArgs>>): boolean;
12+
}

0 commit comments

Comments
 (0)