[英]How to define nodeCategoryProperty function for a Model in typescript?
nodeCategoryProperty
function expects to have the signature - (a: ObjectData, b?: string) => string
, which, IMO, should be (a: ObjectData, b?: string) => string | void
nodeCategoryProperty
function 期望具有签名 - (a: ObjectData, b?: string) => string
,IMO 应该是(a: ObjectData, b?: string) => string | void
(a: ObjectData, b?: string) => string | void
, as this function should not return anything if it is being used as a setter. (a: ObjectData, b?: string) => string | void
,因为这个 function 不应该返回任何东西,如果它被用作设置器。
If the second argument is supplied, the function should modify the node data object so that it has that new category name.如果提供了第二个参数,则 function 应修改节点数据 object 使其具有新的类别名称。
https://gojs.net/latest/api/symbols/Model.html#nodeCategoryProperty https://gojs.net/latest/api/symbols/Model.html#nodeCategoryProperty
For the function I have defined -对于 function 我已经定义了 -
const categoryPropertyFunction = (partData: ObjectData, category?: string): string =>
{
if (category) partData.type = category;
else return partData.type;
};
I am getting TypeScript error:我收到 TypeScript 错误:
TS2366: Function lacks ending return statement and return type does not include 'undefined'. TS2366:Function 缺少结束返回语句并且返回类型不包括“未定义”。
Here is an example of storing the category name as a property of the "d" property on the data object:以下是将类别名称存储为数据 object 上“d”属性的属性的示例:
const model = . . .;
model.nodeCategoryProperty = function (obj: go.ObjectData, str?: string): string {
if (arguments.length > 1) obj.d.category = str;
return obj.d.category;
};
Note the use of function
instead of using an arrow function, so that one can check the number of arguments
.注意使用function
而不是使用箭头 function,以便可以检查arguments
的数量。
The same kind of implementation can be used for the other "...Property" functional properties of the Model classes.相同类型的实现可用于Model类的其他“...Property”功能属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.