xstate icon indicating copy to clipboard operation
xstate copied to clipboard

Bug: Circular type reference in Machine Definition resolves as Actor<any>

Open Necmttn opened this issue 2 years ago • 4 comments

XState version

XState version 5

Description

If i add types for ActorRefFrom to Child and Parent I get a Error: // Type error:

 'A' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.(7022)

Expected result

Expected o circular types to work.

Actual result

Resolves as Actor<any>

Reproduction

https://stackblitz.com/edit/github-7zo8fh?file=src%2Fmain.ts

Additional context

Discord Thread: https://discord.com/channels/795785288994652170/1192785773079052298

Necmttn avatar Jan 06 '24 02:01 Necmttn

This isn't fixable since this relationship is, indeed, circular and TypeScript has to resolve it eagerly. One side has to be typed here without the typeof query to avoid this circularity

Andarist avatar Jan 08 '24 22:01 Andarist

Is there a recommended way of assigning a type here without typeof?

yoshiwarab avatar Mar 28 '24 18:03 yoshiwarab