Global augmentation

Global augmentation

You can also add declarations to the global scope from inside a module:

// observable.ts
export class Observable<T> {
  // ... still no implementation ...
}

declare global {
  interface Array<T> {
    toObservable(): Observable<T>;
  }
}

Array.prototype.toObservable = function () {
  // ...
}

Global augmentations have the same behavior and limits as module augmentations.

doc_TypeScript
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.