Skip to content

Instantly share code, notes, and snippets.

@nathansmith
Last active April 12, 2024 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathansmith/fedc7554944e53422511e5c788a0226c to your computer and use it in GitHub Desktop.
Save nathansmith/fedc7554944e53422511e5c788a0226c to your computer and use it in GitHub Desktop.
Example of JSON in TypeScript.
export type IJson = IJsonArray | IJsonObject | boolean | number | null | string;
export type IJsonArray = IJson[];
/*
=====
NOTE:
=====
This is an `interface` because the reference
can be circular. It would change to `any` if
we simply used a `type`. This does not work…
```
export type IJsonObject = Record<string, IJson>;
```
*/
export interface IJsonObject {
[key: string]: IJson;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment