我有一个 iife
我想编译和我 import
类型的声明。在 TypeScript 版本 3.* 中,它可以正确编译。但是在 TypeScript 版本 4.* 中,它附加了一个 export {}
.有没有办法防止这种情况?
这是 typescript 文件 test.ts
:
import { Tester } from "./tester"
(async function test() : Promise<Tester> { return { hello: "export" } }())
tester.d.ts
export interface Tester {
hello: string
}
带有 TypeScript 4.* 的结果文件 test.js
(async function test() { return { hello: "export" }; }());
export {};
带有 TypeScript 3.9.* 的结果文件 test.js
(async function test() { return { hello: "export" }; }());
我的 tsconfig.json
文件:{
"compilerOptions": {
"target": "ES2020",
"module": "ES2015",
"moduleResolution": "Node",
"strict": true,
"noImplicitAny": true,
"strictFunctionTypes": true,
"strictBindCallApply": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"alwaysStrict": true,
"allowJs": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true,
"outDir": "./public/app",
"skipLibCheck": true
},
"compileOnSave": true,"src/app/meals/add/index.template.js", "src/app/utils/html-template-tag.js" ],
"include": ["src/**/*.ts", "src/**/*.js"],
"exclude": [
"node_modules", "src/**/*spec.ts"
]
}
我用于它的命令:tsc -p ./tsconfig.json
更新 我将此错误报告添加到
TypeScript
.https://github.com/microsoft/TypeScript/issues/41513
最佳答案
这确实是 TypeScript 4.0 的一个有意特性。
更多的
还有其他人的评论也提示仅输入类型:https://github.com/microsoft/TypeScript/issues/38696#issuecomment-720241357
解决方法
module: commonjs
编译关于TypeScript 将 export {} 附加到 TypeScript 4 中的文件末尾,而不是 TypeScript 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64798609/