According to github issues, they have their concerns of not implementing the partial keyword. Therefore, you will need to write it yourself.
This task is no more than mixing prototypes. However, if you want a reliable one, you need to be very careful with method and property conflicts, also with type inference support.
I've written one and published on npm package partial_classes. You can use it by npm i partial_classes. And here is a simple method shows how to do this.
function combineClasses<T>(...constructors: T[]) {
class CombinedClass {
constructor(...args: any[]) {
constructors.forEach(constructor => {
const instance = new constructor(...args); // copy instance property
Object.assign(this, instance);
});
}
}
constructors.forEach(constructor => { // copy prototype property
let proto = constructor.prototype;
while (proto !== Object.prototype) { // iterate until proto chain ends
Object.getOwnPropertyNames(proto).forEach(name => {
const descriptor = Object.getOwnPropertyDescriptor(proto, name);
if (!descriptor) return;
Object.defineProperty(CombinedClass.prototype, name, descriptor);
});
proto = Object.getPrototypeOf(proto);
}
});
return CombinedClass
}
then use as
import combineClasses from 'partial_classes'
class ServiceUrlsFoo { }
class ServiceUrlsBar { }
const ServiceUrls = combineClasses(ServiceUrlsFoo, ServiceUrlsBar)
const instance = new ServiceUrls()