typescript - 打字稿不断在导入上方添加一个函数
问题描述
当 typescript 编译 Javascript 时,它会在顶部添加这个函数
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
}
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
import { PortWidget } from "storm-react-diagrams";
所以我得到了错误
第 14 行:在模块体中导入;重新排序到顶部导入/第一
这是我的 tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": [
"es6",
"dom"
],
"sourceMap": false,
"allowJs": true,
"jsx": "preserve",
"noImplicitReturns": false,
"noImplicitThis": false,
"noImplicitAny": false,
"strictNullChecks": false,
"skipLibCheck": true,
"strict": false,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": false,
"watch": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
// "resolveJsonModule": true,
//"noEmit": true,
"isolatedModules": true
},
"exclude": [
"node_modules",
"build",
"desktop",
"public",
"mobile",
"tests",
"src/player/*"
],
"include": [
"src/admin/react"
]
}
知道我如何解决这个问题吗?
我不明白为什么每次都会添加这个扩展功能。
解决方案
在编译期间,TypeScript 可以生成帮助__extends
程序,以确保相关功能在运行时有效。您可以将它们视为 polyfill。
默认情况下,助手将被内联在每个需要它们的文件中。在您的情况下,这是使用该extends
子句的每个文件。
您可以选择退出此行为并自己提供所需的帮助程序——只是这次它们只会被导入一次。使用--importHelpers
让 TypeScripttslib
为您提取它们。
tsconfig.json
{
"compilerOptions": {
...
"importHelpers": true,
...
}
}
记得tslib
在你的项目中安装:
npm install tslib
阅读手册中有关编译器选项的更多信息。
推荐阅读
- azure-devops - Azure DevOps 的缩写是什么?
- mysql - 2002, "Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)" in docker-compose up
- api - Closure Compiler Service API 缺少 --create_source_map 选项
- ruby-on-rails - 如何在 Rails 中配置 CORS 接受标头
- python - Scraping HTML from array of links
- c# - 遍历列表时获取空值
- ssl - 如何从 Google Cloud Platform 上的负载均衡器中删除 SSL 证书?
- jquery - 如何使用 jquery-ajax 使用复选框制作级联下拉菜单?
- javascript - 获取支持的货币列表
- objective-c - 无法保存文档“queue.h”