Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

381
Views
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, 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'.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!