← Back to Tutorial
TypeScript Compiler
TypeScript Code
Clear
Compile ▶
class User { private id: number; protected name: string; public email: string; constructor(id: number, name: string, email: string) { this.id = id; this.name = name; this.email = email; } getUserId(): number { return this.id; } greet(): string { return `Hello, ${this.name}!`; } } class AdminUser extends User { private permissions: string[]; constructor(id: number, name: string, email: string, permissions: string[]) { super(id, name, email); this.permissions = permissions; } hasPermission(action: string): boolean { return this.permissions.includes(action); } } const admin = new AdminUser(1, "Bob", "bob@example.com", ["read", "write", "delete"]);
Output
Download JS
TypeScript code will be compiled here