typescriptoverridingshadowtypescript2.4

Overriding or shadowing `File` in Typescript


I'm using typescript to write extension scripts for a program that has some objects, like File and Text, that duplicate definitions in lib.d.ts.

As a result, a definition like

declare File(x: string): object;

will cause a duplicate identifier error. Is there a way to selectively override or shadow the library definitions or otherwise replace them with my own?


Solution

  • Is there a way to selectively override or shadow the library definitions or otherwise replace them with my own?

    Two options:

    Use your own lib

    Don't use globals

    E.g. don't call your variable File or window or document or location or other known globals e.g. in node process or global

    Preference

    The second option is ofcourse preferred. Its the cost of working with JavaScript.