Typescript return value wrapped in curly braces?
Asked Answered
H

1

15

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?

Howzell answered 8/6, 2017 at 22:45 Comment(0)
K
18

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

Kimble answered 8/6, 2017 at 22:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.