Allow type aliases to reference themselves in type argument positions
See original GitHub issueTypeScript Version: 3.8.0-dev.20191105
Search Terms: circular
Code
type A<T> = { x: T }
type R = A<R> // FAIL
type B = { x: B } // OK
Expected behavior: Both cases throw no error.
Actual behavior: Type R is rejected due to a circular reference.
Playground Link: Link
Related Issues: https://github.com/microsoft/TypeScript/pull/33050
Regression: https://github.com/microsoft/TypeScript/pull/33050#issuecomment-526637037
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:18 (8 by maintainers)
Top Results From Across the Web
Documentation - Advanced Types - TypeScript
Type aliases create a new name for a type. Type aliases are sometimes similar to interfaces, but can name primitives, unions, tuples, and...
Read more >How to create a circularly referenced type in TypeScript?
The creator of TypeScript explains how to create recursive types here. The workaround for the circular reference is to use extends Array ....
Read more >All About Type Aliases in Kotlin
The big takeaway: Type aliases do not create new types. They simply give another name to an existing type. That, of course, is...
Read more >2515-type_alias_impl_trait - The Rust RFC Book
Allow type aliases and associated types to use impl Trait , replacing the prototype existential type as a way to declare type aliases...
Read more >typing — Support for type hints — Python 3.11.1 documentation
In the function greeting , the argument name is expected to be of type str and the return type str . Subtypes are...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You know how averse someone is to OOP by their initial reaction to
B = { x : B }
=PMy initial reaction was that the recursion has to stop at some point. And that constructing an infinitely recursive type can’t really be performed without
as
casts at some point.But I guess there’s also,
So, I guess I just wasn’t open minded enough =P
When I first saw the types in the original post, my head started screaming, “WHERE IS THE EXIT CONDITION!?”