TypeScript 将 export {} 附加到 TypeScript 4 中的文件末尾,而不是 TypeScript 3

标签 typescript

我有一个 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
  • 设计 session 决定:https://github.com/microsoft/TypeScript/issues/38713

  • 还有其他人的评论也提示仅输入类型:https://github.com/microsoft/TypeScript/issues/38696#issuecomment-720241357
    解决方法
  • 浏览器:用 webpack 编译
  • NodeJS:使用 module: commonjs 编译
  • 关于TypeScript 将 export {} 附加到 TypeScript 4 中的文件末尾,而不是 TypeScript 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64798609/

    相关文章:

    javascript - 类型 'opacity' 上不存在属性 'IntrinsicAttributes',React Native 中 View 不透明度引发抛出和错误

    json - 类型 'Object' 的参数不可分配给类型 'JSON' Httpclient GET 的参数

    typescript - 应用函数名称和参数的函数类型

    TypeScript - 使用 PascalCasing 或 camelCasing 作为模块名称?

    javascript - FormArray(在 Angular6 中): return empty array

    typescript - 以下是什么意思作为类型 : () => void = null

    angular - 从 "angularfire2/database"导入 { AngularFireDatabase, FirebaseListObservable } ;

    javascript - ngAfterViewInit 不工作或者我做错了什么

    typescript - typescript 中类型断言的详细逻辑是什么?

    javascript - 在 Electron-Typescript 应用程序中找不到模块 'jsonfile/utils'