0

I am trying to declare and interface. Basically a user has a collection of roles. I am not able to understand what the right syntax in Typescript for this operation.

export interface User {
    firstName: string;
    lastName: string;
    roles: [Role]
}

export interface Role {
    accountId: string;
    roleId: string;
}
1
  • roles: Role[] Have you tried, reading the docs on Arrays ? Commented Feb 12, 2021 at 10:39

2 Answers 2

0

According to the TypeScript Handbook, you can make a collection of something like so:

export interface Role {
    accountId: string;
    roleId: string;
}

export interface User {
    firstName: string;
    lastName: string;
    roles: Array<Role> // Can also be written as Role[]
}

(Additionally, I think roles and accountId should be kept separate.)

Sign up to request clarification or add additional context in comments.

Comments

0

It is:

export interface User {
    firstName: string;
    lastName: string;
    roles: Role[];
}

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.