deno_doc icon indicating copy to clipboard operation
deno_doc copied to clipboard

support global augmentation

Open mfulton26 opened this issue 4 years ago • 0 comments

I'd like to be able to generate documentation for things added to existing types.

https://www.typescriptlang.org/docs/handbook/declaration-merging.html#global-augmentation

// observable.ts
export class Observable<T> {}
declare global {
  interface Array<T> {
    toObservable(): Observable<T>;
  }
}
Array.prototype.toObservable = function () {
  throw new Error("not implemented");
};

Currently deno doc observable.ts only prints information about class Observable<T> and not about Array<T>#toObservable().

I know that generally this isn't a good idea (prototype pollution) but 1) sometimes it is necessary (e.g. for polyfills for upcoming features) and 2) extending types using a Symbol can safely extend built-ins and other types as symbols avoid name conflicts.

mfulton26 avatar May 18 '21 22:05 mfulton26