TypeScript · Classes and modules

Class

A constructor with typed fields, methods and access modifiers.

Syntax
class User { … }

Example

Example
class User {
  constructor(public id: string, public name: string) {}
  label() { return `${this.name} (${this.id})`; }
}
console.log(new User("u1", "Ada").label());

More in this group

abstract class Access modifiers Declaration file implements Namespace import readonly field 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