JavaScript inline usage of import with typescript 1.6 and es6 syntax

I am looking at updating some older js libs I have to typescript using the ES6 conventions, however I have come across a stumbling point.

So historically when I loaded a JSON file dynamically I would do something like this:

this.someFunctionWhichDoesStuff = function() {
   var config = require(theConfigDir); // theConfigDir was a variable
   // ... other stuffs
}

This worked fine, and I would also in some cases dynamically include some modules from a folder too:

this.someFunctionWhichDoesStuff = function() {
   var actualImplementationToUse = require(theDirectoryWithImplementation); // theConfigDir was a variable
   // ... other stuffs
}

This allowed me to switch implementations based upon configuration at earlier points, and worked well enough. Key points to note here are that the resolvers for the modules are variables not static text and that they are being run inside of functions not at root level.

So with this in mind I went over to the es6 style module inclusion in TS and realised I cannot do the above, as this is not valid syntax:

public someFunctionWhichDoesStuff() {
       import actualImplementationToUse from theDirectoryWithImplementation;
       // ... other stuffs
    }

And it makes sense, as I know ES6 modules need to statically resolve modules, so I am cool with that, however in the typescript 1.6 world I am unsure how to resolve this as var includedModule = require(theDirectory); seems to be invalid as it doesnt know about require, which may be solved with inclusion of the node js d.ts file, however I was hoping someone could give some steering as to what the desired approach is in the new es6 world going forward?

Answer:1

Current my page has a menu bar and iframe section to load the items in the menu bar when clicked. I wanted the iframe to scroll but not the parent page (i want the menu bar fixed to the top). But the ...

Current my page has a menu bar and iframe section to load the items in the menu bar when clicked. I wanted the iframe to scroll but not the parent page (i want the menu bar fixed to the top). But the ...

I have written following code. $("input,textarea").blur(function () { debugger; var val = $.trim($(this).val()); if (val != "") { if (containsHTMLTags(val) == true)...

I have written following code. $("input,textarea").blur(function () { debugger; var val = $.trim($(this).val()); if (val != "") { if (containsHTMLTags(val) == true)...

I tried to add checked property to a specific checkbox using jquery, but it seems doesn't work properly. Checkbox Function Display function product_category_loop_array ($product_category_array = ...

I tried to add checked property to a specific checkbox using jquery, but it seems doesn't work properly. Checkbox Function Display function product_category_loop_array ($product_category_array = ...

EDIT: This is for an Electron project, with a local server spun up on the user's system. So, any concerns about what happens if multiple users attempt simultaneous access can be ignored! My client ...

EDIT: This is for an Electron project, with a local server spun up on the user's system. So, any concerns about what happens if multiple users attempt simultaneous access can be ignored! My client ...

  1. javascript resolve promises sequentially
  2. functional javascript resolving promises sequentially
  3. resolve promises sequential