Skip to content

Commit

Permalink
Consider arrays and tuples within one another as possibly requiring d…
Browse files Browse the repository at this point in the history
…eferral (microsoft#37776)
  • Loading branch information
weswigham authored Apr 3, 2020
1 parent 7cf4b12 commit 7317292
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11858,6 +11858,8 @@ namespace ts {
case SyntaxKind.IndexedAccessType:
case SyntaxKind.ConditionalType:
case SyntaxKind.TypeOperator:
case SyntaxKind.ArrayType:
case SyntaxKind.TupleType:
return isResolvedByTypeAlias(parent);
case SyntaxKind.TypeAliasDeclaration:
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tests/cases/compiler/circularlyReferentialInterfaceAccessNoCrash.ts(1,12): error TS4109: Type arguments for 'Mx' circularly reference themselves.
tests/cases/compiler/circularlyReferentialInterfaceAccessNoCrash.ts(8,16): error TS4109: Type arguments for 'Array' circularly reference themselves.
tests/cases/compiler/circularlyReferentialInterfaceAccessNoCrash.ts(10,18): error TS4110: Tuple type arguments circularly reference themselves.
tests/cases/compiler/circularlyReferentialInterfaceAccessNoCrash.ts(8,16): error TS4110: Tuple type arguments circularly reference themselves.
tests/cases/compiler/circularlyReferentialInterfaceAccessNoCrash.ts(10,19): error TS4110: Tuple type arguments circularly reference themselves.


==== tests/cases/compiler/circularlyReferentialInterfaceAccessNoCrash.ts (3 errors) ====
Expand All @@ -14,10 +14,10 @@ tests/cases/compiler/circularlyReferentialInterfaceAccessNoCrash.ts(10,18): erro
}

type ArrElem = ['list', ArrElem[number][0]][];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS4109: Type arguments for 'Array' circularly reference themselves.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS4110: Tuple type arguments circularly reference themselves.

type TupleElem = [['list', TupleElem[0][0]]];
~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS4110: Tuple type arguments circularly reference themselves.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//// [deferredTypeReferenceWithinArrayWithinTuple.ts]
type TypeStructure =
| ["or", TypeStructure[]] // problem is only here, when using array
| ["string"]
| ["number"]
| ["list", TypeStructure] // with just this it is ok

//// [deferredTypeReferenceWithinArrayWithinTuple.js]
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
=== tests/cases/compiler/deferredTypeReferenceWithinArrayWithinTuple.ts ===
type TypeStructure =
>TypeStructure : Symbol(TypeStructure, Decl(deferredTypeReferenceWithinArrayWithinTuple.ts, 0, 0))

| ["or", TypeStructure[]] // problem is only here, when using array
>TypeStructure : Symbol(TypeStructure, Decl(deferredTypeReferenceWithinArrayWithinTuple.ts, 0, 0))

| ["string"]
| ["number"]
| ["list", TypeStructure] // with just this it is ok
>TypeStructure : Symbol(TypeStructure, Decl(deferredTypeReferenceWithinArrayWithinTuple.ts, 0, 0))

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
=== tests/cases/compiler/deferredTypeReferenceWithinArrayWithinTuple.ts ===
type TypeStructure =
>TypeStructure : TypeStructure

| ["or", TypeStructure[]] // problem is only here, when using array
| ["string"]
| ["number"]
| ["list", TypeStructure] // with just this it is ok
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type TypeStructure =
| ["or", TypeStructure[]] // problem is only here, when using array
| ["string"]
| ["number"]
| ["list", TypeStructure] // with just this it is ok

0 comments on commit 7317292

Please sign in to comment.