nodeCategoryProperty
function expects to have the signature - (a: ObjectData, b?: string) => string
, which, IMO, should be (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.
If the second argument is supplied, the function should modify the node data object so that it has that new category name.
https://gojs.net/latest/api/symbols/Model.html#nodeCategoryProperty
For the function I have defined -
const categoryPropertyFunction = (partData: ObjectData, category?: string): string =>
{
if (category) partData.type = category;
else return partData.type;
};
I am getting TypeScript error:
TS2366: Function lacks ending return statement and return type does not include 'undefined'.
Here is an example of storing the category name as a property of the "d" property on the data object:
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
.
The same kind of implementation can be used for the other "...Property" functional properties of the Model classes.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.