I'm facing a seemingly simple issue that I just can't seem to solve. I have a class called Collection
in an external npm package (let's call it packagename
). In my current project, I want to add some methods to the prototype of that class and notify TypeScript about this change.
The class is defined in the external module like this:
export class Collection<T extends Document> {
// ...
}
Here is what I added to 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>;
}
}
However, when trying to use the new method in another file:
import { Collection } from "packagename"
Collection.prototype.newMethod= function<T extends Document>(this: Collection<T>) {
// ...
};
I encounter the following error:
TS2693: 'Collection' only refers to a type, but is being used as a value here.
The same error occurs if I try importing Collection
with
import * as everything from 'packagename'
and then using everything.Collection
.
What am I overlooking here? Thanks for any insight.