我是靠谱客的博主 醉熏小熊猫,最近开发中收集的这篇文章主要介绍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, 即可

修改后重新运行项目

最后

以上就是醉熏小熊猫为你收集整理的TypeScript项目的问题-第三方包报类型兼容错误的全部内容,希望文章能够帮你解决TypeScript项目的问题-第三方包报类型兼容错误所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(88)

评论列表共有 0 条评论

立即
投稿
返回
顶部