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, 即可

修改後重新運行項目

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