Inheritance
Planned Features
Extends Keyword
Create subclasses that inherit from parent classes:
class Animal { public name: string;
constructor(name: string) { this.name = name; }
public speak(): void { // Default implementation }}
class Dog extends Animal { constructor(name: string) { super(name); }
public speak(): void { // Dog-specific implementation }
public fetch(): void { // Dog-specific method }}Super Calls
Access parent class constructors and methods:
class Parent { public value: i32;
constructor(v: i32) { this.value = v; }}
class Child extends Parent { public extra: i32;
constructor(v: i32, e: i32) { super(v); // Call parent constructor this.extra = e; }}Method Overriding
Override parent methods in subclasses:
class Shape { public area(): f64 { return 0.0; }}
class Rectangle extends Shape { public width: f64; public height: f64;
public area(): f64 { return this.width * this.height; }}
class Circle extends Shape { public radius: f64;
public area(): f64 { return 3.14159 * this.radius * this.radius; }}Polymorphism
Use parent type references for child instances:
function printArea(shape: Shape): void { let a: f64 = shape.area(); // Works with Rectangle, Circle, or any Shape subclass}
function main(): i32 { let rect: Shape = new Rectangle(10.0, 5.0); let circle: Shape = new Circle(3.0);
printArea(rect); // Uses Rectangle.area() printArea(circle); // Uses Circle.area()
return 0;}Current Workaround
Until inheritance is available, you can use composition:
class Dog { public animal: Animal;
constructor(name: string) { this.animal = new Animal(name); }
public getName(): string { return this.animal.name; }}Roadmap
| Feature | Status |
|---|---|
extends keyword | Planned |
super calls | Planned |
| Method overriding | Planned |
| Polymorphic dispatch | Planned |
| Abstract classes | Planned |
Follow progress on GitHub!