1

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.

1
  • 2
    array isn't a built-in type. Did you mean Array? If so then, User[] is just syntactic sugar for Array<User>, and which version you use is purely up to your preferences, but I would prefer User[]. Commented Apr 4, 2019 at 17:18

1 Answer 1

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.