-
模块扩展
// 1.ts export class AClass { public a:string; constructor(a:string) { this.a = a; } }
// 2.ts import { AClass } from './1'; declare module './1' { interface AClass { test: (b: number) => number; } } AClass.prototype.test = (b: number): number => { return b; }
-
全局扩展
// observable.ts
export class Observable<T> {
// ... still no implementation ...
}
declare global {
interface Array<T> {
toObservable(): Observable<T>;
}
}
Array.prototype.toObservable = function () {
// ...
}
网友评论