Async functions are only available when targeting ECMAScript 2015 or
higher.
我认为针对es6意味着编译打字稿的输出javascript将是es6,而es6在大多数浏览器上都不起作用了吗?
这是我的tsconfig.json:
{ "compilerOptions": { "target": "es5","module": "system","moduleResolution": "node","lib": ["es2015","dom"],"sourceMap": true,"emitDecoratorMetadata": true,"experimentalDecorators": true,"removeComments": false,"noImplicitAny": true,"outDir":"js/app/","typeRoots": [ "./node_modules/@types" ] },"exclude": [ "node_modules","app/test" ] }
我想知道lib字段是否可以使它工作,因为它说“es2015”但它没有.
我也在想也许core-js shim可以使异步可用,但我只在我的index.html中包含了这样的垫片:
< script src =“node_modules / core-js / client / shim.min.js”>< / script>
所以我不认为它在编译时使异步可用.有没有更好的方法来导入core-js?
如何使异步可用,但也没有我的代码无法在大多数浏览器上运行?
正如@loganfsmyth对此答案的评论所述,
Just keep in mind that “most major browsers” Could still only cover a
tiny percentage of your user base.
ES6 The ECMAScript 2015 standard,also kNown as ES6,is completely
supported,bringing this major JavaScript evolution to Safari on macOS
and iOS.
你将不得不改变,
"target": "es5",
至
"target": "es6",
TypeScript 1.7 async/await support in ES6 targets (Node v4+) TypeScript Now supports asynchronous functions for engines that have native support for ES6 generators,e.g. Node v4 and above. Asynchronous functions are prefixed with the async keyword; await suspends the execution until an asynchronous function return promise is fulfilled and unwraps the value from the Promise returned.
原文地址:https://www.jb51.cc/angularjs/142325.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。