TypeScript · Classes and modules
readonly field
A field that cannot be reassigned after construction.
Syntax
readonly id: stringExample
Example
class User {
readonly id: string;
constructor(id: string) { this.id = id; }
}More in this group
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.