Alon Alon - 1 month ago 16
TypeScript Question

Adding properties to a nested interface in node.js

In a file named 'some-file.ts' I want to do this:

global.someProp = someVar;


while
global
is a predefined object of type
NodeJS.Global
which is defined in node.d.ts.

How can I make this interface partial?

I've tried all of the following to no avail:

interface Global {
someProp: string;
}

global.someProp = someVar;



interface NodeJS.Global {
someProp: string;
}

global.someProp = someVar;



namespace NodeJS{
interface Global {
someProp: string;
}
}

global.someProp = someVar;


I keep getting:


TS339: Property 'someProp' does not exist on type 'Global'


How can I fix it?

Answer

I've solved it. I had to use the keyword 'declare' as follows:

declare namespace NodeJS{
    interface Global {
        base_dir: string;
    }
}