Reputation: 43
I'm developing an Angular 5 project. I have referenced a third party library downloaded from NPM (odata-v4-ng). I need to augment a class inside this library to add some methods. The class is declared like this.
export declare class ODataQuery extends ODataQueryAbstract {
// methods omitted for brevity
}
I have tried to augment the class this way:
import { ODataQuery } from 'odata-v4-ng';
declare module 'odata-v4-ng' {
interface ODataQuery {
test();
}
}
ODataQuery.prototype.test = () => { };
The problem is that compilers throws saying "'ODataQuery' only refers to a type, but is being used as a value here.". If I create a class in my Angular project and augment it this way, everything works fine.
Any idea?
Upvotes: 3
Views: 569
Reputation: 250036
That specific class is defined in another module and is only reexported by the main odata-v4-ng
module. If you extends the actual module where the class is defined everything seems to work fine:
import { ODataQuery } from 'odata-v4-ng';
declare module './node_modules/odata-v4-ng/src/app/odata/odata-query/odata-query' {
export interface ODataQuery {
test():void
}
}
ODataQuery.prototype.test = () => { };
Upvotes: 1