Skip to content

Commit

Permalink
Bail on unwrapping conditional constraints on the source side when th…
Browse files Browse the repository at this point in the history
…e source conditional is already known to be spooling out of control
  • Loading branch information
weswigham committed Apr 1, 2021
1 parent 363e392 commit b81c98b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
20 changes: 13 additions & 7 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18390,13 +18390,19 @@ namespace ts {
}
}
}
// conditionals _can_ be related to one another via normal constraint, as, eg, `A extends B ? O : never` should be assignable to `O`
// when `O` is a conditional (`never` is trivially aissgnable to `O`, as is `O`!).
const defaultConstraint = getDefaultConstraintOfConditionalType(<ConditionalType>source);
if (defaultConstraint) {
if (result = isRelatedTo(defaultConstraint, target, reportErrors)) {
resetErrorInfo(saveErrorInfo);
return result;


// We'll repeatedly decompose source side conditionals if they're recursive - check if we've already recured on the constraint a lot and, if so, bail
// on the comparison.
if (!isDeeplyNestedType(source, sourceStack, sourceDepth)) {
// conditionals _can_ be related to one another via normal constraint, as, eg, `A extends B ? O : never` should be assignable to `O`
// when `O` is a conditional (`never` is trivially aissgnable to `O`, as is `O`!).
const defaultConstraint = getDefaultConstraintOfConditionalType(<ConditionalType>source);
if (defaultConstraint) {
if (result = isRelatedTo(defaultConstraint, target, reportErrors)) {
resetErrorInfo(saveErrorInfo);
return result;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ tests/cases/compiler/genericConditionalConstrainedToUnknownNotAssignableToConcre
Type 'ReturnType<T[number]>' is not assignable to type 'A'.
Type 'unknown' is not assignable to type 'A'.
Type 'ReturnType<FunctionsObj<T>[number]>' is not assignable to type 'A'.
Type 'unknown' is not assignable to type 'A'.
Property 'x' is missing in type '{}' but required in type 'A'.
Property 'x' is missing in type '{}' but required in type 'A'.


==== tests/cases/compiler/genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts (1 errors) ====
Expand Down Expand Up @@ -37,8 +36,7 @@ tests/cases/compiler/genericConditionalConstrainedToUnknownNotAssignableToConcre
!!! error TS2322: Type 'ReturnType<T[number]>' is not assignable to type 'A'.
!!! error TS2322: Type 'unknown' is not assignable to type 'A'.
!!! error TS2322: Type 'ReturnType<FunctionsObj<T>[number]>' is not assignable to type 'A'.
!!! error TS2322: Type 'unknown' is not assignable to type 'A'.
!!! error TS2322: Property 'x' is missing in type '{}' but required in type 'A'.
!!! error TS2322: Property 'x' is missing in type '{}' but required in type 'A'.
!!! related TS2728 tests/cases/compiler/genericConditionalConstrainedToUnknownNotAssignableToConcreteObject.ts:1:15: 'x' is declared here.
}

Expand Down

0 comments on commit b81c98b

Please sign in to comment.