Defines a type that describes any allowable JSON value, which basically means:
- A JSON value MUST be an
- object
- array
- number
- string
- boolean
- Or one of the following three literal names:
- false
- true
- null
- Can NOT be any of the following:
- function
- undefined
- BigInt
- class
The trick is to use Recursive types
type JSONPrimitive = string | number | boolean | null;
type JSONObject = { [key: string]: JSONValue };
type JSONArray = JSONValue[];
type JSONValue = JSONPrimitive | JSONObject | JSONArray;
From the TypeScript Fundamentals, v3↗ course on FEM↗ taught by Mike North↗.