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

add json type for readJson/writeJson #326

Closed
wants to merge 3 commits into from

Conversation

axetroy
Copy link
Contributor

@axetroy axetroy commented Apr 7, 2019

No description provided.

[member: string]: JSONValue;
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface JSONArray extends Array<JSONValue> {}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can’t this use a type instead of an interface?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good question.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because if I use type

export type JSONPrimitive = string | number | boolean | null;
export type JSONValue = JSONPrimitive | JSONObject | JSONArray;
export interface JSONObject {
  [member: string]: JSONValue;
}
export type JSONArray = Array<JSONValue>

ts will report an error.

Type alias 'JSONValue' circularly references itself.ts(2456)

an ts error or eslint error. I choose the latter.

@kitsonk
Copy link
Contributor

kitsonk commented Apr 10, 2019

There have been long discussions on this in TypeScript land. There is not a good JSON type other than any (see the likes of microsoft/TypeScript#1897 and others). I would just keep it any which allows it to be cast to whatever. If TypeScript ever solves it we can adopt it them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants