Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

382
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda