【问题标题】:vue-cli service ignore typescript type errors on directoryvue-cli 服务忽略目录上的打字稿类型错误
【发布时间】:2019-09-10 04:55:26
【问题描述】:

如何将 vue-cli 工具配置为不对特定文件夹运行类型检查?

  • 我用https://cli.vuejs.org 启动了一个新应用程序
  • 我通过 codegen 生成了一个 jQuery/TypeScript API 目录:src/api/
  • 我在 tslint 文件中忽略了"src/api/**/*.ts",

尝试构建,但 cli 工具也在检查类型错误。

serve 的输出是:

vue-cli-service serve

 INFO  Starting development server...
Starting type checking and linting service...
Using 1 worker with 2048MB memory limit
 98% after emitting CopyPlugin                                                    

 DONE  Compiled successfully in 2701ms                                                                     3:50:28 PM

Type checking and linting in progress...

  App running at:
  - Local:   http://localhost:8080/ 
  - Network: http://192.168.1.32:8080/

  Note that the development build is not optimized.
  To create a production build, run npm run build.

ERROR in /home/me/code/g2/frontend/fe_main/src/api/ms-authentication/api/AuthenticationApi.ts
25:12 Type 'null' is not assignable to type 'JQueryAjaxSettings | undefined'.
    23 |     protected basePath = 'http://localhost';
    24 |     public defaultHeaders: Array<string> = [];
  > 25 |     public defaultExtraJQueryAjaxSettings?: JQueryAjaxSettings = null;
       |            ^
    26 |     public configuration: Configuration = new Configuration();
    27 | 
    28 |     constructor(basePath?: string, configuration?: Configuration, defaultExtraJQueryAjaxSettings?: JQueryAjaxSettings) {
ERROR in /home/me/code/g2/frontend/fe_main/src/api/ms-authentication/api/PasswordApi.ts
25:12 Type 'null' is not assignable to type 'JQueryAjaxSettings | undefined'.
    23 |     protected basePath = 'http://localhost';
    24 |     public defaultHeaders: Array<string> = [];
  > 25 |     public defaultExtraJQueryAjaxSettings?: JQueryAjaxSettings = null;
       |            ^
    26 |     public configuration: Configuration = new Configuration();
    27 | 
    28 |     constructor(basePath?: string, configuration?: Configuration, defaultExtraJQueryAjaxSettings?: JQueryAjaxSettings) {

但如果不修改 codegen 模板,我就无法更改此代码。 :/

【问题讨论】:

  • 正如 htn 指出的那样,这些是 TypeScript 2.0(或更高版本)中的构建错误,其中引入了 strictNullChecks 编译器选项。如果您需要包含此代码,您可以在 tsconfig.json 中禁用 strictNullChecks 以解决构建错误,但您将失去对自己代码的严格检查。

标签: typescript vue.js vue-cli


【解决方案1】:

您应该修改生成的代码或禁用打字稿编译器选项的strictNullChecks。

【讨论】:

    猜你喜欢
    • 2018-05-16
    • 1970-01-01
    • 2019-08-11
    • 1970-01-01
    • 2023-03-20
    • 2021-01-29
    • 2020-10-12
    • 1970-01-01
    • 2020-07-11
    相关资源
    最近更新 更多