Skip to content

Commit

Permalink
conditional types approximation:
Browse files Browse the repository at this point in the history
- improve check to avoid circular code and SOE.
- saw some cases of following typeRefs we couldn't, just be conservative for now and set `skipValidation=true`

followup to e94a5f3
  • Loading branch information
oyvindberg committed Nov 15, 2022
1 parent af663f3 commit 424fb03
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,6 @@ class ImportTree(
|""".stripMargin,
)

/* It's common to nest these things, so handle that */

/**
* Find the first referenced type in the conditional type which
* - is not recursive
Expand All @@ -283,23 +281,22 @@ class ImportTree(
x match {
case tr: TsTypeRef if inferred.contains(tr) => Empty
case aliased =>
ts.FollowAliases(scope)(x) match {
ts.FollowAliases(scope, skipValidation = true)(x) match {
/* It's common to nest these things, so handle that */
case xx: TsTypeConditional if depth < 3 =>
val inferredThis = TsTreeTraverse.collect(xx.pred) { case TsTypeInfer(tp) => TsTypeRef(tp.name) }

lazy val inferredAll: IArray[TsTypeRef] =
inferred ++ inferredThis
val inferredAll: IArray[TsTypeRef] = inferred ++ inferredThis

findCandidates(xx.ifTrue, depth + 1, inferredAll) ++
findCandidates(xx.ifFalse, depth + 1, inferredAll)

// break recursion by referencing back to initial type alias (the depth check is more through)
case typeRef: TsTypeRef if typeRef.name == codePath.forceHasPath.codePath =>
Empty
// keep types which do not refer to inferred types
// keep types which do not refer to inferred types (or back to self)
case _ =>
val referencesInferred = TsTreeTraverse.collect(aliased) {
case tr: TsTypeRef if inferred.contains(tr) => tr
// break recursion by referencing back to initial type alias (the depth check is more through)
case tr: TsTypeRef if tr.name == codePath.forceHasPath.codePath => tr
}
referencesInferred match {
case Empty => IArray(aliased)
Expand Down

0 comments on commit 424fb03

Please sign in to comment.