【问题标题】:No compiler error when using wrong type in TypeScript在 TypeScript 中使用错误类型时没有编译器错误
【发布时间】:2018-10-23 08:21:07
【问题描述】:

我正在使用 Ionic 3 (Angular 5),即使我指定了变量或函数的类型,我使用什么都没关系,它总是像在普通 JS 中一样工作,即没有产生错误。我需要配置一些设置文件(例如 tsconfig.json)还是我遗漏了什么?我什至可以做例如:

foo : string;

foo = someObject as SomeNonExistentClass;

有趣的是,当我运行ionic serve 时,实际上显示了错误,但是当我重新保存其中一个报告错误的文件时,所有错误都消失了。在新的保存/重新编译时也会不时发生。

【问题讨论】:

    标签: typescript ecmascript-6 ionic3 angular5 static-typing


    【解决方案1】:

    可能是 lint 错误,运行 ionic serve 时不会出现 lint 错误,我建议你在 ts-lint 代码编辑器中安装一个扩展,它会在编程时显示 lint 错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-12
      • 2017-11-21
      • 2021-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-02
      相关资源
      最近更新 更多