TypeScript
TypeScript copied to clipboard
Intermittent circular type error
Bug Report
🔎 Search Terms
is referenced directly or indirectly in its own type annotationdirectly or indirectlyown type annotation
🕗 Version & Regression Information
- This is a crash
- I initially saw this in 4.3.2 and can still receive in 4.4.4
⏯ Playground Link
Playground link with relevant code GitHub link with relevant code
💻 Code
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
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 where this module is within references
🙂 Expected behavior
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 beforehand, but had no luck
Does this still reproduce in typescript@next?
I had been running this with typescript@^4.5.1-rc and still see this issue.
I tried specifically with typescript@next, aka [email protected]
[~/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 8.22s.
[~/src/virtualstate/x]$ echo "make some change here"
[~/src/virtualstate/x]$ yarn build
yarn run v1.22.10
$ tsc -b ./tsconfig.repo.json && yarn build:post
packages/fringe/src/source.ts:46:3 - error TS2502: 'children' is referenced directly or indirectly in its own type annotation.
46 children: CreateNodeChildrenWithSourceType<T[], ChildrenResult<ReturnType<T>>[]>;
~~~~~~~~
Found 1 error.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Cleaning the workspace (removing all tsconfig.tsbuildinfo) resolves the error.
Can confirm still present in 4.6.0-dev.20211208
I can also confirm this is present in 4.7.4. Our current "fix" is also to delete the tsconfig.tsbuildinfo file.