Repository: TypeScript
Issue: Intermittent circular type error 
Labels: Needs Investigation,Rescheduled

# Bug Report

<!--
  Please fill in each section completely. Thank you!
-->

### 🔎 Search Terms

- `is referenced directly or indirectly in its own type annotation`
- `directly or indirectly`
- `own type annotation` 

<!--
  What search terms did you use when trying to find an existing bug report?
  List them here so people in the future can find this one more easily.
-->

### 🕗 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 a crash
- I initially saw this in 4.3.2 and can still receive in 4.4.4

### ⏯ 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/?target=99&module=1#code/FAegVGwARlCCUDOBjAhgG1QJyQewK5bICmUWxAZseQHYlQAuAFqg1GjVAEakNao1EAWwCWDBsQAmUXDkQNZU6GBDAGATwAOpALLZELdOikBlAkWIAlStWJ1SAXiR8RNAOZQAPlBr4hPHG8uXFxjAS8oACERNwBJGgYAblAIZXgkNEw5c3pyKloSABpGJhFEdgJ0aR4oYjEmajIbAtcPVCgAbwABdFcAaygAOVYRADdiADVB3EliAF8ZHDzbOlaoSRFyZDZEHOJlNIREdX9Q9gEaXDYa+UVJYrFagA8yhnLcGnR1KFcoTSxcCREIhlKoNNooGZCCRrPk7PQnHosAYMMZJFCLLCVvRvMdTuhksBXBIsBRUPQpjNSB1oE04fYAFyQvZYgrEZJQGSaBgiD6IAD8TNwXAAVsRthy8NDiIKoPgaH1LgB3GiS5ClKq0W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kkJDKYy3M9A4LSN4Lw8lttB8KM3o6oxqdM7BrcgY-MwlhY1SMsyo8tsiBRC47MOs3Y2doacdXs54yEwk5E2rhELBuDqJsc+kzrmjscLc3U3rpPIbpoMbi008GboIhburJ07bkQv08OCSL3kPVSNhvotMrfBFs+i-PEgPUYpmcunYlMl3ZAtQbeKkzpCXdQNfEfRMF3DZhQ9mSqsI3ME5KSa-Fhp+kOlCwJpvP3Z-H8hVqFI3jGtCh-VjBMBgFQTVLSHONy+gJOlwvouwgAKqYMO6yYA6byCvCuLaiuqNtbLzzblOLZyvECcokZirBSO4yt6oCs8uatapMp8oRZ5NERTX0uWBMRpacs2ust6vO7EoasitDonJjaytGv6uHaGtCu1gRbXyPl+PVTBQhskCCR+u8vOv9ZRsBuupBueoRPRWfYqsZ5xtdzJv8BFXWujJ73GgOtKGNAxtPYZsKvuupoakCrp7q5lsRa1m5t2tDpmqFsybKElsE51sJuKunMzTVsZ6A5du8ZWu0aNAOsVb2sPYDuI5DtuQWs0Z+TjtrrNsbqttOs1vTtBxZ7RRswtxwAq7ZT4RCCIDqY3lKKa77v8DqD8ajuCajKxCOuybJDGxnwf3QOwOlr15KLFJutARmqXuHsSDHvmqjLNhAOzDPu7vUL6LQNmoTAUsEsvabYd3gJouOI4tYB4t7CmiNn5sYdYfSg4fWWFMtw1hQNf3YeIcRZEse37WUNTUIvksfzgs0tATvuUcWomtyqWjZ6xSuZ56LQJCpTS7lAtyHQ1DkBCC4DjCSBF41M6QQNMDkeH2UeEu7VASe30es2McUvVoTAMr6LWbEaJFUeuo0d7VxN8b0v9w2UMb9xUvEWY4GoodQv4eQscfFD9xrJtvFs+dybbqvsVtsISuZVCOYNBLQcVvRJtZODmYQcgaKsLko1rWyRekSRGmBQRewyKuIrhvpV5dZccsVuOpZusCfZZOhPnNJP4zMSBdARZpVtOCaMxOFfLv1eaC9uiwVfe05OWfZMtcOhAA)
[GitHub link with relevant code](https://github.com/virtualstate/x/blob/51a837be89e0fe2e6ca171080f3ceb03f5b2d13a/packages/fringe/src/source.ts#L46)

### 💻 Code

<!-- Please post the relevant code sample here as well-->
```ts
type CreateNodeResultCoreOp1<T extends CreateNodeOp1Function, O extends Options = Options, C extends unknown[] = [], Depth extends number = MaxDepth> = Omit<FragmentVNode, "source" | "children"> & {
  source: T;
  children: CreateNodeChildrenWithSourceType<T[], ChildrenResult<ReturnType<T>>[]>;
};
```

### 🙁 Actual behavior

<!-- What happened, and why it was wrong -->

When I change code within the module containing the above type, I get a build error:

```
[~/src/virtualstate/x]$ yarn build
yarn run v1.22.10
$ tsc -b ./tsconfig.repo.json && yarn build:post
packages/fringe/src/source.ts:41:3 - error TS2502: 'children' is referenced directly or indirectly in its own type annotation.

41   children: CreateNodeChildrenWithSourceType<T[], ChildrenResult<ReturnType<T>>[]>;
     ~~~~~~~~


Found 1 error.
```

When I clean the modules (remove tsconfig.tsbuildinfo), the error is resolved. 

`CreateNodeChildrenWithSourceType`, and `ChildrenResult` don't directly reference the types that lead back to `CreateNodeResultCoreOp1`, which rules out direct reference, but I guess `tsconfig.tsbuildinfo` somehow creates an indirect reference.

I pulled the types out and they work with typescript playground (linked above)

I am directly running [`tsc -b ./tsconfig.repo.json`](https://github.com/virtualstate/x/blob/51a837be89e0fe2e6ca171080f3ceb03f5b2d13a/package.json#L25) where this module is within [references](https://github.com/virtualstate/x/blob/51a837be89e0fe2e6ca171080f3ceb03f5b2d13a/tsconfig.repo.json#L8)

### 🙂 Expected behavior

<!-- What you expected to happen instead, and why -->

No build error (which happens when I'm only changing code outside of this module). 

```
[~/src/virtualstate/x]$ yarn build    
yarn run v1.22.10
$ tsc -b ./tsconfig.repo.json && yarn build:post
$ node correct-import-extensions.js
✨  Done in 3.00s.
```

Majority of the time development is going smooth now while working around this, I had ran into this error in the past which had me give up on these types, not knowing that `tsconfig.tsbuildinfo` was causing the problem rather than just the complex types being a problem. 

Any info here would be helpful, but I fully expect there to be not a straightforward resolution for this, and to just remove `tsconfig.tsbuildinfo` whenever I get this error. 

I had also reached out for help on this in the [discord](https://discord.com/channels/508357248330760243/746338083146039297/901051831470415882) beforehand, but had no luck