Skip to content
Closed
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: 3 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14558,9 +14558,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
constraint = getConstraintOfTypeParameter(typeVariable);
}
else {
const modifiersConstraint = getConstraintOfType(getModifiersTypeFromMappedType(type));
if (modifiersConstraint) {
constraint = getApparentType(modifiersConstraint);
const modifiersType = getModifiersTypeFromMappedType(type);
if (modifiersType) {
constraint = getApparentType(getConstraintOfType(modifiersType) || modifiersType);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not particularly fond of this - maybe there is a better way of doing this. This mainly tries to get the apparent type of the modifiers type when the modifiers type is a mapped type itself (like in Mapped<Mapped2<Foo>>). Mapped types don't return anything from getConstraintOfType.

}
}
if (constraint && everyType(constraint, isArrayOrTupleType)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//// [tests/cases/compiler/nestedHomomorphicMappedTypesWithArrayConstraint1.ts] ////

=== nestedHomomorphicMappedTypesWithArrayConstraint1.ts ===
interface SinonMatcher {
>SinonMatcher : Symbol(SinonMatcher, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 0, 0))

and(expr: SinonMatcher): SinonMatcher;
>and : Symbol(SinonMatcher.and, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 0, 24))
>expr : Symbol(expr, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 1, 6))
>SinonMatcher : Symbol(SinonMatcher, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 0, 0))
>SinonMatcher : Symbol(SinonMatcher, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 0, 0))

or(expr: SinonMatcher): SinonMatcher;
>or : Symbol(SinonMatcher.or, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 1, 40))
>expr : Symbol(expr, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 2, 5))
>SinonMatcher : Symbol(SinonMatcher, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 0, 0))
>SinonMatcher : Symbol(SinonMatcher, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 0, 0))

test(val: any): boolean;
>test : Symbol(SinonMatcher.test, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 2, 39))
>val : Symbol(val, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 3, 7))
}

type MatchArguments<T> = {
>MatchArguments : Symbol(MatchArguments, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 4, 1))
>T : Symbol(T, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 6, 20))

[K in keyof T]: SinonMatcher | T[K];
>K : Symbol(K, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 7, 3))
>T : Symbol(T, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 6, 20))
>SinonMatcher : Symbol(SinonMatcher, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 0, 0))
>T : Symbol(T, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 6, 20))
>K : Symbol(K, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 7, 3))

};

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

calledWith(...args: Partial<MatchArguments<TArgs>>): boolean;
>calledWith : Symbol(SinonSpyCallApi.calledWith, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 10, 56))
>args : Symbol(args, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 11, 13))
>Partial : Symbol(Partial, Decl(lib.es5.d.ts, --, --))
>MatchArguments : Symbol(MatchArguments, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 4, 1))
>TArgs : Symbol(TArgs, Decl(nestedHomomorphicMappedTypesWithArrayConstraint1.ts, 10, 26))
}

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

=== nestedHomomorphicMappedTypesWithArrayConstraint1.ts ===
interface SinonMatcher {
and(expr: SinonMatcher): SinonMatcher;
>and : (expr: SinonMatcher) => SinonMatcher
>expr : SinonMatcher

or(expr: SinonMatcher): SinonMatcher;
>or : (expr: SinonMatcher) => SinonMatcher
>expr : SinonMatcher

test(val: any): boolean;
>test : (val: any) => boolean
>val : any
}

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

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

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

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

interface SinonMatcher {
and(expr: SinonMatcher): SinonMatcher;
or(expr: SinonMatcher): SinonMatcher;
test(val: any): boolean;
}

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

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