Repository: TypeScript
Issue: False positive for Circular dependency error
Labels: Help Wanted,Possible Improvement

# Bug Report

Hello. First of all want to express my love to TypeScript and admit of all work you did for the best typing system I've ever known.

I believe I found a bug where three points are touched: type inference, recursive types and variadic params. The bug doesn't happen when you take off any of this points. I put the reproduction code below.

I believe that it's a bug because the main recursive feature works fine for `composite` that has slightly complicated signature. Also, I can make `failing` working by making a union with a dummy type, so it's

```
failing: AComponent<[ARows | 'never']>
```

The bug doesn't happen when I have the direct components type without infering:

```
type AComponentTypes = {
  simple: [string],
  composite: [string, ARows]
  failing: [ARows]
}
```

The bug doesn't happen when I don't use variadic types:

```
type ARowUnion<U> = U extends keyof AComponents ? [U, AArgument<AComponents[U]>] : never
```

Is there any other workarounds besides defining a union`ARows | 'never'` ?

I spent about 4 hours struggling with this so I hope this is a helpful finding. Thank you


<!--
  Please fill in each section completely. Thank you!
-->

### 🔎 Search Terms

typescript, generic types, variadic types, composition, recursion, self reference, mapped types, false positive

### 🕗 Version & Regression Information

<!-- When did you start seeing this bug occur?

"Bugs" that have existed in TS for a long time are very likely to be FAQs; refer to
  https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs

If possible, please try testing the nightly version of TS to see if it's already been fixed.
For npm: `typescript@next`
This is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly

Note: The TypeScript Playground can be used to try older versions of TypeScript.

Please keep and fill in the line that best applies:
-->
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about 
- I was unable to test this on prior versions because variadic types were not implemented.
- There is no working version. 4.0.5. still has the problem, but 3.9.7 seems not supporting variadic types.

### ⏯ Playground Link

<!--
  A link to a TypeScript Playground "Share" link which shows this behavior

  The TypeScript Workbench can be used for more complex setups, try
  https://www.typescriptlang.org/dev/bug-workbench/

  As a last resort, you can link to a repo, but these will be slower for us to investigate.
-->
[Playground link with relevant code](https://www.typescriptlang.org/play?ssl=25&ssc=1&pln=1&pc=1#code/C4TwDgpgBAggwgewLZgQOwm4BnKBeKAbwCgopsBLFAGwgC5ZEV1NgAeAbW2ACcK0A5gF0AfABpSUAMbJUGLA3iyWWTtz6CxsAEoIA7tlGSAZgEMK1fgMVM5rTjF0GjAX2LFQkRsvnsAKlAQAB7AmAAmuACuaADWaPpoHKL4UAAUpjwC2Ax+AJT4IlAAbggUYe6e0DAwmZFI9n6FBAHBoWgR3sy+bPzGEDxQAGqFAPxDUAwYRf0V4FVOAKpoFOhsC01QC4Eh4bgxECAIxp12WLhjHAtaAHS31bX1qkpdrNiXokITUFMzHnM6+hSjn0SxWaDY+0Ox2epxwIj+XmBBiBTiS7hkaG4UB4+myAL0SRSHEkHAA5JQaBBSVpSQAJCDUagIKB6BA8ahhUlCCRkMkyF5YalQUlIEBQMAZUxIIXEsi88lUMC0IV0hlMllsjlcnlQITckmkswWKwyyTyilKqk0+mM5ms9mc-VkPXEITEIA)

### 💻 Code

<!-- Please post the relevant code sample here as well-->
```ts
type AComponents = {
  simple: AComponent<[string]>,
  composite: AComponent<[string, ARows]>
  failing: AComponent<[ARows]>
}

type AComponent<T extends unknown[]> = (args: T) => void

type AArgument<T> = T extends AComponent<infer V> ? V : never

type ARowUnion<U> = U extends keyof AComponents ? [U, ...AArgument<AComponents[U]>] : never

type ARow = ARowUnion<keyof AComponents>
type ARows = ARow[]

const rows: ARow[] = [
  ['simple', 'Hello world'],
  ['composite', 'my param', [
    ['simple', 'Hello world'],
  ]],
  ['failing', [
    ['simple', 'Hello world'],
  ]]
]
```

### 🙁 Actual behavior

Type alias 'ARow' circularly references itself.
Type arguments for 'Array' circularly reference themselves.

### 🙂 Expected behavior

There is no errors for the types definitions, both `failing` and `component` types are valid and allows recursive structures.