Skip to content
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
28 changes: 5 additions & 23 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2053,7 +2053,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
var noConstraintType = createAnonymousType(/*symbol*/ undefined, emptySymbols, emptyArray, emptyArray, emptyArray);
var circularConstraintType = createAnonymousType(/*symbol*/ undefined, emptySymbols, emptyArray, emptyArray, emptyArray);
var resolvingDefaultType = createAnonymousType(/*symbol*/ undefined, emptySymbols, emptyArray, emptyArray, emptyArray);
var resolvingApparentMappedType = createAnonymousType(/*symbol*/ undefined, emptySymbols, emptyArray, emptyArray, emptyArray);

var markerSuperType = createTypeParameter();
var markerSubType = createTypeParameter();
Expand Down Expand Up @@ -14539,32 +14538,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
}

function getApparentTypeOfMappedType(type: MappedType) {
if (type.resolvedApparentType) {
if (type.resolvedApparentType === resolvingApparentMappedType) {
return type.resolvedApparentType = type;
}
return type.resolvedApparentType;
}
type.resolvedApparentType = resolvingApparentMappedType;
return type.resolvedApparentType = getResolvedApparentTypeOfMappedType(type);
return type.resolvedApparentType || (type.resolvedApparentType = getResolvedApparentTypeOfMappedType(type));
}

function getResolvedApparentTypeOfMappedType(type: MappedType) {
const mappedType = type.target as MappedType || type;
const typeVariable = getHomomorphicTypeVariable(mappedType);
if (typeVariable && !mappedType.declaration.nameType) {
let constraint: Type | undefined;
if (!type.target) {
constraint = getConstraintOfTypeParameter(typeVariable);
}
else {
const modifiersConstraint = getConstraintOfType(getModifiersTypeFromMappedType(type));
if (modifiersConstraint) {
constraint = getApparentType(modifiersConstraint);
}
}
const typeVariable = getHomomorphicTypeVariable(type);
if (typeVariable && !type.declaration.nameType) {
const constraint = getConstraintOfTypeParameter(typeVariable);
if (constraint && everyType(constraint, isArrayOrTupleType)) {
return instantiateType(mappedType, prependTypeMapping(typeVariable, constraint, mappedType.mapper));
return instantiateType(type, prependTypeMapping(typeVariable, constraint, type.mapper));
}
}
return type;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//// [tests/cases/compiler/nestedHomomorphicMappedTypesWithArrayConstraint1.ts] ////

=== nestedHomomorphicMappedTypesWithArrayConstraint1.ts ===
// Based on @types/sinon v10

type MatchArguments<T> = {
>MatchArguments : Symbol(MatchArguments, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 0, 0))
>T : Symbol(T, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 2, 20))

[K in keyof T]: T[K];
>K : Symbol(K, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 3, 5))
>T : Symbol(T, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 2, 20))
>T : Symbol(T, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 2, 20))
>K : Symbol(K, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 3, 5))

};

interface SinonSpyCallApi<TArgs extends any[] = any[]> {
>SinonSpyCallApi : Symbol(SinonSpyCallApi, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 4, 2))
>TArgs : Symbol(TArgs, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 6, 26))

calledWith(...args: Partial<MatchArguments<TArgs>>): boolean;
>calledWith : Symbol(SinonSpyCallApi.calledWith, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 6, 56))
>args : Symbol(args, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 7, 15))
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --))
>MatchArguments : Symbol(MatchArguments, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 0, 0))
>TArgs : Symbol(TArgs, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 6, 26))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//// [tests/cases/compiler/nestedHomomorphicMappedTypesWithArrayConstraint1.ts] ////

=== nestedHomomorphicMappedTypesWithArrayConstraint1.ts ===
// Based on @types/sinon v10

type MatchArguments<T> = {
>MatchArguments : MatchArguments<T>

[K in keyof T]: T[K];
};

interface SinonSpyCallApi<TArgs extends any[] = any[]> {
calledWith(...args: Partial<MatchArguments<TArgs>>): boolean;
>calledWith : (...args: Partial<MatchArguments<TArgs>>) => boolean
>args : Partial<MatchArguments<TArgs>>
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps leave this test in?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it confusing to have tests that are kinda meant to pass but they fail?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well the fact that the test was added meant that the behavior wasn't tested in the first place. Capturing the behavior and changes over time is useful.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remember to leave the tests in the future.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @strict: true
// @noEmit: true

// Based on @types/sinon v10

type MatchArguments<T> = {
[K in keyof T]: T[K];
};

interface SinonSpyCallApi<TArgs extends any[] = any[]> {
calledWith(...args: Partial<MatchArguments<TArgs>>): boolean;
}