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

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

ERROR  ERROR in /Users/***/Desktop/AJK/****/****/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/AJK/***/******/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, 即可

修改后重新运行项目

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章