Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

383
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda