Fred Hors
Fred Hors

Reputation: 4116

Why the error "Generic type 'Record' requires 2 type argument(s). ts(2314)" using this form of typing?

I'm trying to use this type but I can't:

type ROLES = "one" | "two"

type Users = {
    name: Record<[key in ROLES]?, User[]>;
};

because it throws with:

Generic type 'Record' requires 2 type argument(s). ts(2314)

Why?

Upvotes: 4

Views: 7336

Answers (1)

Dean
Dean

Reputation: 551

The error message says it all. you have to define two generics, so if you want the key to be a key of ROLES then you need to remove the ? and use Record<ROLES, User[]>. if you want optional entries you can use Partial<Record<ROLES, User[]>>.

Upvotes: 3

Related Questions