Skip to content

More Recursive Type Declarations #9074

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

Closed
opensrcken opened this issue Jun 10, 2016 · 2 comments
Closed

More Recursive Type Declarations #9074

opensrcken opened this issue Jun 10, 2016 · 2 comments
Labels
Duplicate An existing issue was already created Question An issue which isn't directly actionable in code

Comments

@opensrcken
Copy link

TypeScript Version:

nightly

Code

// A self-contained demonstration of the problem follows...
type Json = string | number | boolean | null | JsonObject | JsonArray;
type JsonObject = { [key:string]: Json };
type JsonArray = Array<Json>;

Expected behavior:
Compiles.

Actual behavior:
Type alias 'Json' circularly references itself.
Type alias 'JsonArray' circularly references itself.

As a workaround, I'm using the more verbose:

declare type Json = JsonObject | number | string | JsonArray;
declare type JsonArray = IMaybeRecursiveArray<JsonObject | number | string>;
interface IMaybeRecursiveArray<T> {
  [i: number]: T | IMaybeRecursiveArray<T>;
}
interface JsonObject {
  [paramKey: string]: Json
}

But FlowType can compile the more "direct" type declarations. It would be nice if Typescript could support this as well.

@mhegazy
Copy link
Contributor

mhegazy commented Jun 10, 2016

please see #3496 (comment)

@DanielRosenwasser DanielRosenwasser added Question An issue which isn't directly actionable in code Duplicate An existing issue was already created labels Jun 10, 2016
@opensrcken
Copy link
Author

I definitely never saw that comment. My apologies.

@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
Duplicate An existing issue was already created Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

3 participants