Get a union of property names from a type.

Section: Type Operators

Use `keyof`

typescript
typescript
type User = { id: number; name: string };
type UserKeys = keyof User; // "id" | "name"
Explanation

`keyof` is foundational for many advanced type helpers.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Type Operators
Use `typeof` in types
Infer a type from an existing value.
OpenIn sheettypescriptsame section
Use indexed access types
Get a nested property type from another type.
OpenIn sheettypescriptsame section
Use template literal types
Compose string literal types from smaller pieces.
OpenIn sheettypescriptsame section
Constrain a key parameter with `keyof`
Accept only valid property names for a given object type.
OpenIn sheettypescript2 tag match
Generic identity function
Use a type parameter for reusable function typing.
OpenIn sheettypescript1 tag match
Simple mapped type
Create a type by iterating over keys.
OpenIn sheettypescript1 tag match