Код: Выделить всё
class Model {
constructor(schema) {
Object.assign(this, schema);
}
static define(prototype) {
const Subclass = class extends this {
}
// in reality, I attach getters/setters here with some logic using defineProperties
Object.assign(Subclass.prototype, prototype);
return Subclass;
}
}
class MyModel extends Model.define({
foo: 'str' // initialization schema
}) {
}
// const MyModel2 = MyModel.define(...)
const schema = new MyModel({ bar: 2});
console.log(schema.foo);
console.log(schema.bar);
< /code>
Так что я не вижу, как возвращать класс, который расширяет это, и назначает новые реквизиты на его прототип. Кажется, мне нужно что-то подобное:
(упрощенный D.TS Pseudocode) < /p>
type Constructor = new (...args: any[]) => T;
class Model {
static define(this: Constructor, prototypeProps: P): class extends T {[key in keyof prototypeProps]: prototypeProps[key]}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... h-given-pr