Loading...
const roles = ['admin', 'editor'] as const;
type Role = 'admin' | 'editor';const roles = ['admin', 'editor'] as const;
type Role = (typeof roles)[number];[number] reads the element type of the const array, so the union follows the runtime list.
User[key] with a runtime variable and getting a 'used as a type' error.User['id'], or typeof key when the key is a variable.T[number], e.g. (typeof roles)[number] for a const array.Index with keyof: T[keyof T] gives the union of every property type.
Yes, chain the lookups: User['address']['city'].