You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, compile es6/7 code to es5/3 will emit generated code to local file. For example, if we write a file as follow:
functionp(): Promise<number>{returnnewPromise<number>((resolve)=>{setTimeout(()=>resolve(1),1e3)})}asyncfunctionnext(){constvalue=awaitp()console.log('next value %s',value)constnext=awaitp()returnnext}constret=next()console.log('return: %s',ret)ret.then((value)=>console.log('promise returned value: %s',value))
Set the target to es5, the compile result as follow:
The generated file is so large! If we use async/await in each project file, will emit a mass of useless code.
How about separate the emited functions to a separated module, and use require to load it?
For example:
var__awaiter=require('typescript/libs/awaiter');var__generator=require('typescript/libs/generator');functionp(){returnnewPromise(function(resolve){setTimeout(function(){returnresolve(1);},1e3);});}functionnext(){return__awaiter(this,void0,void0,function(){varvalue,next;return__generator(this,function(_a){switch(_a.label){case0: return[4/*yield*/,p()];case1:
value=_a.sent();console.log('next value %s',value);return[4/*yield*/,p()];case2:
next=_a.sent();return[2/*return*/,next];}});});}varret=next();console.log('return: %s',ret);ret.then(function(value){returnconsole.log('promise returned value: %s',value);});
The text was updated successfully, but these errors were encountered:
Currently, compile
es6/7
code toes5/3
will emit generated code to local file. For example, if we write a file as follow:Set the target to
es5
, the compile result as follow:The generated file is so large! If we use
async/await
in each project file, will emit a mass of useless code.How about separate the emited functions to a separated module, and use
require
to load it?For example:
The text was updated successfully, but these errors were encountered: