当使用typescript扩展现有扩展时,如何在tiptap中的声明中添加自定义命令



我正在尝试从tiptap扩展表扩展,并添加一个额外的命令。

declare module '@tiptap/core' {
interface Commands<ReturnType> {
table: {
setTableClassName: () => ReturnType;
};
}
}
export const CustomTable = Table.extend({
addAttributes() {}, 
addCommands() {}
})

当我添加上面的代码时,我得到以下错误

Subsequent property declarations must have the same type.  Property 'table' must be of type '{ insertTable: (options?: { rows?: number | undefined; cols?: number | undefined; withHeaderRow?: boolean | undefined; } | undefined) => ReturnType; addColumnBefore: () => ReturnType; ... 16 more ...; setCellSelection: (position: { ...; }) => ReturnType; }', but here has type '{ setTableClassName: () => ReturnType; }'.ts(2717)
table.d.ts(14, 9): 'table' was also declared here.

我该如何解决此问题?

我遇到了类似的问题,我认为这是因为表已经被使用了,请尝试将declare中的table更改为您自己的名称,例如customTable,然后在函数CustomTable 中设置名称

declare module '@tiptap/core' {
interface Commands<ReturnType> {
customTable: {
setTableClassName: () => ReturnType;
};
}
}
export const CustomTable = Table.extend({
name: "customTable",
addAttributes() {}, 
addCommands() {}
})

请记住,您的表节点现在将具有名称";customTable";

最新更新