typescript - 是否让变量:typeof import('large-module'); 将整个模块导入内存?
问题描述
对于以下代码段:
let variable: typeof import('large-module');
async function expensiveOperation () {
variable = await import('large-module');
// ...do stuff
}
在调用函数之前是否将“大模块”加载到内存中?
(因为导入是写在类型定义中的)
解决方案
它不是。打字稿将静态解析打字。您可以在编译的 javascript 中看到它:
let variable;
async function expensiveOperation() {
variable = await import('large-module');
}
推荐阅读
- python - Django - 尽管遵循文档,但自定义 handler500 无法正常工作
- java - 我如何检查数组中的任何整数是否具有相同的位数,例如 24、54、67,如下例所示
- c# - 首次启动 C# 控制台应用程序时的不同行为
- r - R ggplot2:仅显示图例中的形状
- javascript - 如果我在复选框 = 未选中时尝试选择下拉列表,则需要验证错误消息
- reactjs - Faced Object 文字只能指定 React Typescript 中的已知属性
- python - 为什么在使用 pandas 数据框时可以使用方括号来同时引用列标签和行索引?
- html - 如何制作具有相同宽度百分比的响应式表格?
- c# - 泛型类型参数 C# 中的方差关键字(输入、输出)名称推理
- javascript - ASP.NET Core with - 当对数据库进行某些更改时,使用 SignalR 刷新 UI