1

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?

Alon
  • 10,381
  • 23
  • 88
  • 152
  • Possible duplicate of [How to use global variable in node.js?](http://stackoverflow.com/questions/10987444/how-to-use-global-variable-in-node-js) – Steeve Pitis Oct 11 '16 at 08:34
  • @SteevePitis no! It's a completely different question. – Alon Oct 11 '16 at 08:36
  • Then try to explain your goal in a different way because I've never seen those keyword in js `namespace` & `interface` – Steeve Pitis Oct 11 '16 at 08:44
  • @SteevePitis my question is completely about TypeScript and using partial interface which is a feature of TypeScript. The question you referred is not about TypeScript at all! – Alon Oct 11 '16 at 08:44
  • Ok, say this in your title ;) – Steeve Pitis Oct 11 '16 at 08:45
  • @SteevePitis my question is about TypeScript, not JavsScript. – Alon Oct 11 '16 at 08:45
  • @SteevePitis instead of changing the title, Endless has removed the 'javascript' tag, so it's clear now. Thank you. – Alon Oct 11 '16 at 08:46
  • Btw since your are running this on NodeJS and TypeScript is only sugar in front of Javascript ... the answer will probably not be so far ... – Steeve Pitis Oct 11 '16 at 08:47
  • @Steeve Pitis don't jinx! It's been 37 hours and no answers yet! – Alon Oct 12 '16 at 21:16

1 Answers1

1

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

declare namespace NodeJS{
    interface Global {
        base_dir: string;
    }
}
Alon
  • 10,381
  • 23
  • 88
  • 152