Home > Enterprise >  Why the error "Generic type 'Record' requires 2 type argument(s). ts(2314)" usin
Why the error "Generic type 'Record' requires 2 type argument(s). ts(2314)" usin

Time:07-12

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?

CodePudding user response:

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[]>>.

  • Related