-
Notifications
You must be signed in to change notification settings - Fork 396
Open
Description
实现 JsonifiedObject
工具类型,用于对 object
对象类型进行序列化操作。具体的使用示例如下所示:
type JsonifiedObject<T extends object> = // 你的实现代码
type MyObject = {
str: "literalstring",
fn: () => void,
date: Date,
customClass: MyClass,
obj: {
prop: "property",
clz: MyClass,
nested: { attr: Date }
},
}
declare class MyClass {
toJSON(): "MyClass";
}
/**
* type JsonifiedMyObject = {
* str: "literalstring";
* fn: never;
* date: string;
* customClass: "MyClass";
* obj: JsonifiedObject<{
* prop: "property";
* clz: MyClass;
* nested: {
* attr: Date;
* };
* }>;
* }
*/
type JsonifiedMyObject = Jsonified<MyObject>;
declare let ex: JsonifiedMyObject;
const z1: "MyClass" = ex.customClass;
const z2: string = ex.obj.nested.attr;
请在下面评论你的答案
Metadata
Metadata
Assignees
Labels
No labels