Issue
Why does this work:
type Foo = { x: Foo }
but this doesn't:
type Bar<A> = { x: A }
type Foo = Bar<Foo>
// ^^^ Type alias 'Foo' circularly references itself
Shouldn't they be equivalent?
Solution
Per the documentation, a type alias can refer to itself in a property, but not anywhere else on the right side of the declaration:
We can also have a type alias refer to itself in a property
So, as you noted, this works:
type Foo = { x: Foo }
However, it’s not possible for a type alias to appear anywhere else on the right side of the declaration
But this fails:
type Foo = Bar<Foo>
Answered By - Seamus
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.