【发布时间】:2021-06-16 07:52:10
【问题描述】:
运行此代码片段后,我将以下数据结构打印到控制台
let editorDelta: DeltaStatic | undefined = editor?.getContents()
console.log(editorDelta)
控制台:
ops: [
{
attributes: {
underline: true,
italic: true,
color: "#000fff",
background: "#fff000",
bold: true
},
insert: "this"
},
{
attributes: {
underline: true,
italic: true,
color: "#000fff",
background: "#fff000",
bold: true
},
insert: "that"
},
]
我正在尝试为此数据创建类型变量,但遇到了一些问题。下面的界面正在工作,但我想为一些更嵌套的数据定义类型,如属性和插入分机。
interface DeltaStatic {
ops?: object[]
}
我尝试过但不起作用的其他一些示例。
interface DeltaStatic {
ops?: {
attributes: {
underline: boolean,
italic: boolean,
color: string,
background: string,
bold: boolean
},
insert: string
}[]
}
interface DeltaStatic {
ops?: [
{
attributes: {
underline: boolean,
italic: boolean,
color: string,
background: string,
bold: boolean
},
insert: string
}
]
}
【问题讨论】:
标签: typescript tsx