This seems so trivial, yet I fail to make it work.
I have a class Collection in an external npm dependency (say packagename). In my current project, I would like to add some methods to the prototype of that class, and informing TS of that fact.
In the external module, the class is defined like :
export class Collection<T extends Document> {
// ...
}
So here is what I wrote in an external.d.ts file in my project :
import { Document } from "packagename";
declare module "packagename" {
export interface Collection<T extends Document> {
newMethod(): Promise<T | null>;
}
}
But then in another file :
import { Collection } from "packagename"
Collection.prototype.newMethod= function<T extends Document>(this: Collection<T>) {
// ...
};
fails with the following error :
TS2693: 'Collection' only refers to a type, but is being used as a value here.
Same goes if I import Collection with import * as everything from 'packagename' then everything.Collection.
What am I missing here ? Thanks.