K
K
Konstantin2020-01-31 12:11:04
typescript
Konstantin, 2020-01-31 12:11:04

How can a TypeScript entry be shortened?

return this.layerService.getLayerItems(layer.groupNode.id).map((item: LayerItemGenericDecription) => {
       let {title, description }  = this.layersSemanticService.getTitleDescription(item, layer.groupNode.id);
       item.title = title;
       item.description = description;
      return item;
    });


Is it possible to do something like this:

return {irem.title, item.description} =  this.layersSemanticService.getTitleDescription(item, layer.groupNode.id);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2020-01-31
@Junart1

it's better that way

return this.layerService.getLayerItems(layer.groupNode.id)
  .map((item: LayerItemGenericDecription) => {
    const { title, description }  = this.layersSemanticService.getTitleDescription(item, layer.groupNode.id);
    return { ...item, ...{ title, description }};
  });

And if getTitleDescription does not produce anything else, then title and description are not needed either.
It is better not to mutate the original item, you never know what it will affect.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question