Typescript return value wrapped in curly braces?

In the following block of heros code, curly braces are wrapped:

  export class InMemoryDataService implements InMemoryDbService { createDb() { let heroes = [ {id: 11, name: 'Mr. Nice'}, {id: 12, name: 'Narco'}, ... ]; return {heroes}; } } 

In particular, for this?

+5
source share
1 answer

Yes, you return it as an object that looks like this:

 { heroes: heroes } 

This is a shortcut to use this form: { heroes } .

More on this here: Object Initializer - New Conventions in ECMAScript 2015

+8
source

Source: https://habr.com/ru/post/1268682/


All Articles