TypeScript项目的问题-第三方包报类型兼容错误

在nuxt项目中,引用了AntV包,1.0.3版本时报了这样子的错误

ERROR  ERROR in /Users/***/Desktop/***/****/****/node_modules/@antv/g2plot/lib/plots/pie/component/label/base-label.d.ts(17,18):                                           nuxt:typescript 10:33:23
17:18 Interface 'PieLabelConfig' incorrectly extends interface 'Pick<Label, "visible" | "style" | "type" | "formatter" | "offsetX" | "offsetY" | "precision" | "suffix" | "position" | "adjustColor" | "adjustPosition" | "autoRotate">'.
  Types of property 'formatter' are incompatible.
    Type '((text: string, item: any, idx: number) => string) | undefined' is not assignable to type '((text: string | number | null | undefined, item: any, idx: number, ...extras: any[]) => string) | undefined'.
      Type '(text: string, item: any, idx: number) => string' is not assignable to type '(text: string | number | null | undefined, item: any, idx: number, ...extras: any[]) => string'.
        Types of parameters 'text' and 'text' are incompatible.
          Type 'string | number | null | undefined' is not assignable to type 'string'.
            Type 'undefined' is not assignable to type 'string'.
    15 |     textBaseline?: string;
    16 | }
  > 17 | export interface PieLabelConfig extends Omit<Label, 'offset'> {
       |                  ^
    18 |     visible: boolean;
    19 |     formatter?: (text: string, item: any, idx: number) => string;
    20 |     /** whether */
ERROR  ERROR in /Users/***/Desktop/***/***/******/node_modules/@antv/g2plot/lib/plots/pie/layer.d.ts(17,92):                                                                nuxt:typescript 10:33:23
17:92 Type 'T' does not satisfy the constraint 'ViewLayerConfig'.
  Type 'PieLayerConfig' is not assignable to type 'ViewLayerConfig'.
    Types of property 'label' are incompatible.
      Type 'PieLabelConfig | undefined' is not assignable to type 'Label | undefined'.
        Type 'PieLabelConfig' is not assignable to type 'Label'.
          Types of property 'formatter' are incompatible.
            Type '((text: string, item: any, idx: number) => string) | undefined' is not assignable to type '((text: string | number | null | undefined, item: any, idx: number, ...extras: any[]) => string) | undefined'.
              Type '(text: string, item: any, idx: number) => string' is not assignable to type '(text: string | number | null | undefined, item: any, idx: number, ...extras: any[]) => string'.
    15 | export interface PieLayerConfig extends PieViewConfig, LayerConfig {
    16 | }
  > 17 | export default class PieLayer<T extends PieLayerConfig = PieLayerConfig> extends ViewLayer<T> {
       |                                                                                            ^
    18 |     static getDefaultOptions(): any;
    19 |     pie: any;
    20 |     type: string;

这个错误是包版本存在的类型兼容错误.

对于这种第三方包的错误影响到了项目的构建,可以通过设置tsconfig.json文件来跳过对第三方包的校验。

设置参数:"skipLibCheck":true, 即可

修改后重新运行项目

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
vue-typescript-import-dts 是一个用于为 Vue.js 项目中的 TypeScript 文件生成类型声明文件的工具。在 Vue.js 项目中使用 TypeScript 进行开发时,我们经常需要为一些第三方库或自定义组件编写类型声明文件,以提供更好的代码提示和类型检查。 使用 vue-typescript-import-dts 工具可以自动分析 TypeScript 文件中的导入语句,并根据导入的模块生成对应的类型声明文件。这样,在使用该模块时,IDE 或编辑器就能提供准确的代码补全和类型检查。 例如,假设我们的项目中使用了一个名为 axios 的第三方库进行网络请求,但是该库并没有提供类型声明文件。我们可以通过 vue-typescript-import-dts 工具,在我们的 TypeScript 文件中导入 axios,并正确配置工具,它将自动为我们生成一个 axios.d.ts 类型声明文件。 具体使用 vue-typescript-import-dts 的步骤如下: 1. 在项目中安装 vue-typescript-import-dts,可以使用 npm 或 yarn 命令来安装。 2. 在 TypeScript 文件中,使用 import 语句导入需要生成类型声明文件的模块。 3. 在项目根目录下创建一个 .vue-typescript-import-dts.json 配置文件,用来配置生成类型声明文件的规则。可以指定生成的声明文件的输出路径、文件名等。 4. 运行 vue-typescript-import-dts 命令,它会自动扫描 TypeScript 文件中的导入语句,并根据配置生成相应的类型声明文件。 这样,在我们编写代码时,IDE 或编辑器就可以准确地为我们提供代码补全和类型检查的功能。这对于提高开发效率和代码质量非常有帮助。 总之,vue-typescript-import-dts 是一个便捷的工具,可以自动为 Vue.js 项目中使用的第三方库或自定义组件生成类型声明文件,提供更好的代码提示和类型检查功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值