I see that declaration merging allows me to declare new methods on classes from external modules, which I can define by assigning a function to a property on the class's prototype:
import { Observable } from "./observable";
declare module "./observable" {
interface Observable<T> {
map<U>(f: (x: T) => U): Observable<U>;
}
}
Observable.prototype.map = function (f) {
// ... another exercise for the reader
}
What I want instead is to declare new properties on the class, which I may either assign directly or define with Object.defineProperty
:
import { Observable } from "./observable";
declare module "./observable" {
interface Observable<T> {
name: string;
}
}
Object.defineProperty(Observable.prototype, 'name', {
get: function getName () {
return 'whatever I want'
}
}
Is there any way to do this?