Syntax

TypeScript Get Keys with keyof Syntax

In TypeScript, get keys with keyof: creates a union of an object type's keys — type Keys = keyof User;

Quick Answer

Syntax
type Keys = keyof User;
TypeScriptSyntax

Get Keys with keyof

Code example
type Keys = keyof User;

Creates a union of an object type's keys.

Learn More

How to get keys with keyof in TypeScript

  1. Open your TypeScript file or editor.
  2. Copy the example, then replace its sample names and values for your code.

TypeScript Get Keys with keyof Syntax

Use type Keys = keyof User;.

Related Syntax References

Frequently asked questions

What is the TypeScript syntax for get keys with keyof?

Use this pattern: type Keys = keyof User;

Can I copy this TypeScript code example?

Yes. Use Copy code and adapt the example to your program.

Is this TypeScript syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify