Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<key> is referenced directly or indirectly in its own type annotation #22018

Closed
KiaraGrouwstra opened this issue Feb 17, 2018 · 2 comments
Closed
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed

Comments

@KiaraGrouwstra
Copy link
Contributor

KiaraGrouwstra commented Feb 17, 2018

TypeScript Version: 2.8.0-dev.20180217

Search Terms:

  • "is referenced directly or indirectly in its own type annotation"

Code

type Flatten<T> = {
  '1': Flatten<T extends Array<infer U> ? U : T>;
}[T extends number ? '1' : '1'];

(as mentioned in #21613)

Expected behavior: ok

Actual behavior:

error TS2502: ''1'' is referenced directly or indirectly in its own type annotation.

Playground Link: needs 2.8, playground is on 2.7

Related Issues: #6230

I saw similar issues on other types, though the greatest common denominator appeared to be recursion + conditional types (?).

@mhegazy
Copy link
Contributor

mhegazy commented Mar 10, 2018

Type aliases are just that, aliases. the compiler will try to resolve the alias target once it sees it, if that causes it to loop over itself, then you will get the error. in this case a use of Flatten needs a constraint to be verified, and to do that the compiler will pull on the type, and will get into the cycle.

@mhegazy mhegazy added the Design Limitation Constraints of the existing architecture prevent this from being fixed label Mar 10, 2018
@typescript-bot
Copy link
Collaborator

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed
Projects
None yet
Development

No branches or pull requests

3 participants