顶层 await 不会等待其依赖项
作者: qingwabote创建于 2023年11月26日更新于 2024年9月2日
标签bug
演示
a.ts
let a:string;
// 使用 async/await 来实现延迟
async function delay():Promise<void> {
return new Promise(function(resolve) {
setTimeout(() => {
resolve();
}, 1000);
})
}
// 等待延迟执行完毕
await delay();
// 修改 a 的值
a = 'a';
export {a};b.ts
import {a} from './a.js'
console.log('a in b',a)c.ts
import {a} from './a.js'
console.log('a in c',a)index.ts
export * from './a.js'
export * from './b.js'
export * from './c.js'index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script src="./dist/s.js"></script>
<script type="systemjs-module" src="./dist/index.js"></script>
</body>
</html>tsconfig.json
{
"compilerOptions": {
"target": "ES2017",
"module": "System",
"moduleResolution": "node",
"allowJs": true,
"sourceMap": false,
"outDir": "dist",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}使用 tsc 将代码编译为 systemjs 模块,并启动 web 服务器
内容来源: systemjs/systemjs