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
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.