0

All in title,

e.g.

users: User[];
users: array<User>;

What is the difference? Is there one a better practice than the other?

nb: I couldn't find information about this & I see both in source code.

PierreD
  • 860
  • 1
  • 14
  • 30
  • `array` isn't a built-in type. Did you mean `Array`? If so then, `User[]` is just syntactic sugar for `Array`, and which version you use is purely up to your preferences, but I would prefer `User[]`. – p.s.w.g Apr 04 '19 at 17:18

1 Answers1

0

users: User[]; is a valid type.

users: array<User>; is not a valid type. You will get an error Cannot find name 'array'.

You can create your interface like below.

export interface Person {
    users: User[];
}

export interface User {
    firstName: string;
    lastName: string;
}
Damien
  • 1,582
  • 1
  • 13
  • 24