extending basic types

Topics: General
Oct 5, 2012 at 8:40 PM

I was struggling a bit how to deal with tsc recognizing extensions of basic JavaScript types like String and Function. One solution was to modify the lib.d.ts file, but that didn't seem right.

Now I just found out that interfaces are also open. So to be able to call for example the sync method on a function without tsc complaining, I just included the following in my declaration file:

interface Function {  
    sync(thisArg: any, ...argArray: any[]): any;

and now I can just use my normal code like

var txt = fs.readFile.sync(.....);


Just thought I share my findings since I saw some emails from people facing similar problems. TS is really starting to grow on me. Great job!

Oct 8, 2012 at 3:15 PM

Thanks for sharing!