-
-
Notifications
You must be signed in to change notification settings - Fork 255
Conversation
ESNext Dynamic Import!
946b863
to
db765e1
Compare
Awesome, I haven't had a moment to look into the implementation - will be interesting to see if they are emitting the System.register support for it. |
@guybedford I got a chance to look into this a bit recently and the results seem promising. Compiling the following code import('jquery').then(({default: $}) => {
$('div').text('您好');
}); into the System.register([], function (exports_1, context_1) {
var __moduleName = context_1 && context_1.id;
return {
setters: [],
execute: function () {
context_1.import('jquery').then(({ default: $ }) => {
$('div').text('您好');
});
}
};
}); Does this look correct? If I understand the intent of the spec correctly, it is possible for the behavior of a dynamic import to be affected by arbitrary dynamic context associated with the importing module which is why the import is transpiled into There is also a new module target Unfortunately, there appears to be bug on the type checking side that fails to apply the |
I just re-read your comment in the TS repo and this does indeed appear to be correct. |
Thanks for checking this out, great to hear it's working ok. Yes exactly the context allows relative module names to work out relative to the runtime parent.
Oh dear, well hopefully this can be sorted out soon. I still wish TypeScript would just get on board with microsoft/TypeScript#16093 (comment). |
I absolutely agree. The good news is that the TypeScript team does seem to be recommending the Unfortunately, there is a seemingly endless plethora of tutorials and even official documentation for libraries such as moment.js that give bad advice to TypeScript users who continue to write more and more non standard code that will turn into broken code. With respect to the async import type checking bug, I filed microsoft/TypeScript#17444. |
By the way, dynamic import is now available to TypeScript users in plugin-typescript as of frankwallis/plugin-typescript#209 released in 7.1.0 |
ESNext Dynamic Import!