【问题标题】:ng build --watch is not outputting dist directory if there is a transpilation error如果存在编译错误,ng build --watch 不会输出 dist 目录
【发布时间】:2018-06-12 14:11:17
【问题描述】:

我的终端中有这个命令

$ ng build --watch
Date: 2018-01-02T21:42:45.851Z                                                      
Hash: f72a8ce7baf664dc5d5a
Time: 3260ms
chunk {inline} inline.bundle.js, inline.bundle.js.map (inline) 5.83 kB [entry] [rendered]
chunk {main} main.bundle.js, main.bundle.js.map (main) 303 bytes [initial] [rendered]
chunk {polyfills} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 323 bytes [initial] [rendered]
chunk {styles} styles.bundle.js, styles.bundle.js.map (styles) 57.9 kB [initial] [rendered]

ERROR in src/main.ts(50,42): error TS2339: Property 'value' does not exist on type 'HTMLElement'.

即使使用ng build 出现错误,我如何强制转译?无论如何,我希望 angular-cli 始终将目标文件输出到 dist 导演。

【问题讨论】:

标签: javascript node.js angular-cli ng-build


【解决方案1】:

推荐的方法是使用类型断言:

let inputFields = document.getElementsByClassName("settings") as HTMLInputElement

TypeScript bug 中所述。

基于angular-cliconfiguration options,在构建过程中无法抑制错误。

您需要使用类型断言修复您的 TypeScript 代码,将变量强制转换为类型 any,或者在您的 tsconfig.json 文件中使用配置标志 - 例如 "compilerOptions":{ "noImplicitAny":false },您可以使用 read more about here.

有关 TypeScript 编译器选项的完整列表,请参阅:

https://www.typescriptlang.org/docs/handbook/compiler-options.html

【讨论】:

  • 为了所有阅读本文的人,人们应该使用 tsconfig.json 中的哪些配置选项来忽略错误
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-16
  • 1970-01-01
  • 2017-08-30
  • 1970-01-01
  • 2021-01-12
  • 2020-11-13
相关资源
最近更新 更多