TypeScript v1.5, possibility to require in a specific part of code

47 views Asked by At

Context

I m developping an application in which I need to load an array in a method like

 getRouteFromLink(link:String):Array {
        array = require(link);
        return array;
    }

Does it exist something giving me the possibilité to make without declaring it at the top of the file ?

1

There are 1 answers

0
jhchen On BEST ANSWER

Sure, Typescript supports Optional Module Loading. From the Handbook:

declare var require;
import Zip = require('./ZipCodeValidator');
if (needZipValidation) {
    var x: typeof Zip = require('./ZipCodeValidator');
    if (x.isAcceptable('.....')) { /* ... */ }
}