当我在 ts 代码中出现错误时,如何使用 tsconfig 文件强制 TypeScript 不编译为 JS?

问题描述 投票:0回答:3

我在默认文件中没有找到:tsc --init

我的配置文件

github代码

{
  "compilerOptions" : {
      "target": "ES3",
      "module": "ES2015",
      "declaration": false,
      "sourceMap": true,
      "outDir": "./dist",
      "rootDir": "./src",
      
      "watch": true
  },
  
 
  "include": [
      "src/**/*"
  ]
} 
javascript reactjs typescript webpack tsconfig
3个回答
6
投票

您需要在 tsconfig.json 中添加

noEmitOnError: true

此标志控制如果报告任何错误,打字稿编译器是否应生成输出文件。默认情况下它是 false,这意味着即使存在错误,编译器仍然会发出输出文件。

https://www.typescriptlang.org/tsconfig#noEmitOnError


0
投票

我也有同样的问题。 我在

tsconfig
属性之后删除了
compilerOptions
中的 src。然后
tsc
命令开始显示类型错误和导入。


0
投票

将它们附加到 config.json 中,而不是在每次导入后添加扩展(ts)。

{
    "noEmit": true,
    "allowImportingTsExtensions": true
}
© www.soinside.com 2019 - 2024. All rights reserved.