Typescript return value wrapped in curly braces?

7.1k Views Asked by At

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?

1

There are 1 best solutions below

0
Nitzan Tomer On BEST ANSWER

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