question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow type aliases to reference themselves in type argument positions

See original GitHub issue

TypeScript 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:open
  • Created 4 years ago
  • Reactions:1
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
AnyhowStepcommented, Nov 13, 2019

You know how averse someone is to OOP by their initial reaction to B = { x : B } =P

1reaction
AnyhowStepcommented, Nov 10, 2019

My 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,

class SelfRecursive {
  self : SelfRecursive;
  constructor () {
    this.self = this;
  }
}

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!?”

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found