TypeScript · Classes and modules

readonly field

A field that cannot be reassigned after construction.

Syntax
readonly id: string

Example

Example
class User {
  readonly id: string;
  constructor(id: string) { this.id = id; }
}

More in this group

abstract class Access modifiers Class Declaration file implements Namespace import Type-only import

Learn this in the course

Reference pages are the quick answer. The course explains the why, shows the full example and ends with a challenge.

Open the course