Syntax

TypeScript Readonly Property Syntax

In TypeScript, readonly property: prevents a property from being reassigned — interface Point { readonly x: number; }

Quick Answer

Syntax
interface Point { readonly x: number; }
TypeScriptSyntax

Readonly Property

Code example
interface Point { readonly x: number; }

Prevents a property from being reassigned.

Learn More

How to readonly property in TypeScript

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

TypeScript Readonly Property Syntax

Use interface Point { readonly x: number; }.

Related Syntax References

Frequently asked questions

What is the TypeScript syntax for readonly property?

Use this pattern: interface Point { readonly x: number; }

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