Skip to content

Instantly share code, notes, and snippets.

@karol-majewski
Created July 19, 2020 12:44
Show Gist options
  • Save karol-majewski/98794005860f926e573db3cd33ed889e to your computer and use it in GitHub Desktop.
Save karol-majewski/98794005860f926e573db3cd33ed889e to your computer and use it in GitHub Desktop.
JSONLike type in TypeScript
type JSONLike =
| { [property: string]: JSONLike }
| readonly JSONLike[]
| string
| number
| boolean
| null;
interface Serializable {
toJSON(): JSONLike;
}
class MyClass implements Serializable {
map = new Map<string, string>();
toJSON() {
// return this.map; Error
return Object.fromEntries(this.map.entries())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment