ope*_*sas 6 json typescript typescript-typings
我想输入一个变量,该变量应该是能够使用 JSON.stringify 序列化的对象。
我找到了这个定义,但我想知道是否有一些内置类型,或者更好的方法来做到这一点:
export type JSONObject = { [key: string]: JSON }
export interface JSONArray extends Array<JSON> {}
export type JsonValue = null | string | number | boolean | JSONArray | JSONObject
Run Code Online (Sandbox Code Playgroud)
在我看来,这应该是很常见的事情。
this 没有内置类型,但从 Typescript 3.7 开始可以简化为:
type Json = string | number | boolean | null | Json[] | { [key: string]: Json };
Run Code Online (Sandbox Code Playgroud)
有关递归类型别名的更多信息,请参见此处。
| 归档时间: |
|
| 查看次数: |
817 次 |
| 最近记录: |