Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript return value wrapped in curly braces?

In the following code block heros is wrapped with curly braces:

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

In particular reason for this?

like image 255
Ole Avatar asked Jun 08 '17 22:06

Ole


1 Answers

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

{
    heroes: heroes
}

It's a "shortcut" to use this form: { heroes }.

More on this here: Object initializer - New notations in ECMAScript 2015

like image 93
Nitzan Tomer Avatar answered Sep 20 '22 19:09

Nitzan Tomer