Syntax

TypeScript Literal Type Syntax

In TypeScript, literal type: restricts a value to specific literals — type Dir = "left" | "right";

Quick Answer

Syntax
type Dir = "left" | "right";
TypeScriptSyntax

Literal Type

Code example
type Dir = "left" | "right";

Restricts a value to specific literals.

Learn More

How to literal type in TypeScript

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

TypeScript Literal Type Syntax

Use type Dir = "left" | "right";.

Related Syntax References

Frequently asked questions

What is the TypeScript syntax for literal type?

Use this pattern: type Dir = "left" | "right";

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