【发布时间】:2021-12-31 05:27:36
【问题描述】:
nodeCategoryProperty 函数需要签名 -
(a: ObjectData, b?: string) => string,IMO 应该是 (a: ObjectData, b?: string) => string | void,因为如果这个函数被用作 setter,它不应该返回任何东西。
如果提供了第二个参数,函数应该修改节点数据 对象,使其具有新的类别名称。
https://gojs.net/latest/api/symbols/Model.html#nodeCategoryProperty
对于我定义的函数-
const categoryPropertyFunction = (partData: ObjectData, category?: string): string =>
{
if (category) partData.type = category;
else return partData.type;
};
我收到 TypeScript 错误:
TS2366:函数缺少结束返回语句并且返回类型不包括“未定义”。
【问题讨论】:
-
"IMO, 应该是 (a: ObjectData, b?: string) => string | void" 但显然不是,因为你使用你的假设。为什么不符合 1. 文档给你的接口 2. 似乎正确匹配你不使用时得到的错误?
标签: javascript typescript gojs