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

Circular references in type declarations can be made using objects but not arrays #14016

Closed
jameswilddev opened this issue Feb 11, 2017 · 1 comment
Labels
Design Limitation Constraints of the existing architecture prevent this from being fixed

Comments

@jameswilddev
Copy link

TypeScript Version: 2.1.4-insiders.20161201

https://www.typescriptlang.org/play/index.html#src=type%20SelfRefObj%20%3D%20%22A%22%20%7C%20%7B%20%5Bkey%3A%20string%5D%3A%20SelfRefObj%20%7D%0D%0Atype%20SelfRefArr%20%3D%20%22A%22%20%7C%20%5BSelfRefArr%5D

Expected behavior:

Either both objects and arrays in type declarations can reference the type being declared, or neither.

Actual behavior:

Objects may reference the type being declared, but arrays throw an error

Use case:

Defining valid JSON as a type:
type Json = boolean | number | string | null | { [key: string]: Json } | [Json]

@ahejlsberg
Copy link
Member

This is a known design limitation. However, you can use an intermediate interface type as described here.

@ahejlsberg ahejlsberg added the Design Limitation Constraints of the existing architecture prevent this from being fixed label Feb 12, 2017
@mhegazy mhegazy closed this as completed Apr 21, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 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