Dev Highlights

Доки по разработке

This project is maintained by teniryte

Современные миксины

Принципы

Пример

type Constructor = new (...args: any[]) => {};

function Scale<TBase extends Constructor>(Base: TBase) {
  return class Scaling extends Base {
    private _scale = 1;
    setScale(scale: number) {
      this._scale = scale;
    }
    get scale() {
      return this._scale;
    }
  };
}

type GConstructor<T = {}> = new (...args: any[]) => T;
type Positionable = GConstructor<{ setPos(x: number, y: number): void }>;

function Jumpable<TBase extends Positionable>(Base: TBase) {
  return class extends Base {
    jump() {
      this.setPos(0, 20);
    }
  };
}

Практика