antd,`tsc`获取错误:接口' treeprops< t>'错误地扩展了接口< treeprops< t>

发布于 2025-02-08 19:46:41 字数 4035 浏览 1 评论 0原文

我想创建在项目内使用ANTD的React软件包,但是当我运行npm run build时,它会在tsc tsc

返回此错误

node_modules/antd/lib/tree-select/index.d.ts:18:18 - error TS2430: Interface 'TreeSelectProps<ValueType, OptionType>' incorrectly extends interface 'Omit<TreeSelectProps<ValueType, OptionType>, "mode" | "getInputElement" | "inputIcon" | "backfill" | "showTreeIcon" | "treeMotion" | "treeLine">'.
  Types of property 'switcherIcon' are incompatible.
    Type 'SwitcherIcon' is not assignable to type 'IconType'.
      Type '(props: { expanded: boolean; }) => ReactNode' is not assignable to type 'IconType'.
        Type '(props: { expanded: boolean; }) => ReactNode' is not assignable to type '(props: TreeNodeProps<DataNode>) => ReactNode'.
          Types of parameters 'props' and 'props' are incompatible.
            Type 'TreeNodeProps<DataNode>' is not assignable to type '{ expanded: boolean; }'.
              Types of property 'expanded' are incompatible.
                Type 'boolean | undefined' is not assignable to type 'boolean'.
                  Type 'undefined' is not assignable to type 'boolean'.

18 export interface TreeSelectProps<ValueType = any, OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType> extends Omit<RcTreeSelectProps<ValueType, OptionType>, 'showTreeIcon' | 'treeMotion' | 'inputIcon' | 'mode' | 'getInputElement' | 'backfill' | 'treeLine'> {
                    ~~~~~~~~~~~~~~~

node_modules/antd/lib/tree/Tree.d.ts:86:18 - error TS2430: Interface 'TreeProps<T>' incorrectly extends interface 'Omit<TreeProps<T>, "direction" | "draggable" | "prefixCls" | "showLine">'.
  Types of property 'icon' are incompatible.
    Type 'ReactNode | ((nodeProps: AntdTreeNodeAttribute) => ReactNode)' is not assignable to type 'IconType'.
      Type '(nodeProps: AntdTreeNodeAttribute) => ReactNode' is not assignable to type 'IconType'.
        Type '(nodeProps: AntdTreeNodeAttribute) => ReactNode' is not assignable to type '(props: TreeNodeProps<DataNode>) => ReactNode'.
          Types of parameters 'nodeProps' and 'props' are incompatible.
            Type 'TreeNodeProps<DataNode>' is not assignable to type 'AntdTreeNodeAttribute'.
              Types of property 'eventKey' are incompatible.
                Type 'Key | undefined' is not assignable to type 'string'.
                  Type 'undefined' is not assignable to type 'string'.

86 export interface TreeProps<T extends BasicDataNode = DataNode> extends Omit<RcTreeProps<T>, 'prefixCls' | 'showLine' | 'direction' | 'draggable'> {
                    ~~~~~~~~~

我的软件包中

{ 
         "main": "dist/index.js",
         "typings": "dist/index.d.ts",
          "dependencies": {
         "@babel/polyfill": "^7.12.1",
         "@testing-library/jest-dom": "^5.16.4",
         "@testing-library/react": "^13.3.0",
         "@testing-library/user-event": "^13.5.0",
         "@types/jest": "^27.5.2",
         "@types/node": "^16.11.41",
         "@types/react": "^18.0.14",
         "@types/react-dom": "^18.0.5",
         "antd": "^4.16.0",
         "react": "^18.2.0",
         "react-dom": "^18.2.0",
         "react-scripts": "5.0.1",
         "styled-components": "^5.3.5",
         "ts-loader": "^9.3.0",
         "typescript": "^4.7.3",
         "web-vitals": "^2.1.4",
         "webpack": "^5.73.0",
         "webpack-cli": "^4.10.0"
       },
       "scripts": {
         "start": "react-scripts start",
         "emit-types": "tsc",
         "emit": "tsc --outDir dist --declaration --emitDeclarationOnly",
         "build": "babel src/lib --out-dir dist --extensions '.ts,.tsx' && npm run emit-types && NODE_ENV=production webpack",
         "test": "react-scripts test",
         "eject": "react-scripts eject"
       },
     }

。 “ https://i.sstatic.net/wthpt.jpg” rel =“ nofollow noreferrer”> error_image

I want to create react package that use Antd inside project, but when I run npm run build it return this error on tsc step

Error

node_modules/antd/lib/tree-select/index.d.ts:18:18 - error TS2430: Interface 'TreeSelectProps<ValueType, OptionType>' incorrectly extends interface 'Omit<TreeSelectProps<ValueType, OptionType>, "mode" | "getInputElement" | "inputIcon" | "backfill" | "showTreeIcon" | "treeMotion" | "treeLine">'.
  Types of property 'switcherIcon' are incompatible.
    Type 'SwitcherIcon' is not assignable to type 'IconType'.
      Type '(props: { expanded: boolean; }) => ReactNode' is not assignable to type 'IconType'.
        Type '(props: { expanded: boolean; }) => ReactNode' is not assignable to type '(props: TreeNodeProps<DataNode>) => ReactNode'.
          Types of parameters 'props' and 'props' are incompatible.
            Type 'TreeNodeProps<DataNode>' is not assignable to type '{ expanded: boolean; }'.
              Types of property 'expanded' are incompatible.
                Type 'boolean | undefined' is not assignable to type 'boolean'.
                  Type 'undefined' is not assignable to type 'boolean'.

18 export interface TreeSelectProps<ValueType = any, OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType> extends Omit<RcTreeSelectProps<ValueType, OptionType>, 'showTreeIcon' | 'treeMotion' | 'inputIcon' | 'mode' | 'getInputElement' | 'backfill' | 'treeLine'> {
                    ~~~~~~~~~~~~~~~

node_modules/antd/lib/tree/Tree.d.ts:86:18 - error TS2430: Interface 'TreeProps<T>' incorrectly extends interface 'Omit<TreeProps<T>, "direction" | "draggable" | "prefixCls" | "showLine">'.
  Types of property 'icon' are incompatible.
    Type 'ReactNode | ((nodeProps: AntdTreeNodeAttribute) => ReactNode)' is not assignable to type 'IconType'.
      Type '(nodeProps: AntdTreeNodeAttribute) => ReactNode' is not assignable to type 'IconType'.
        Type '(nodeProps: AntdTreeNodeAttribute) => ReactNode' is not assignable to type '(props: TreeNodeProps<DataNode>) => ReactNode'.
          Types of parameters 'nodeProps' and 'props' are incompatible.
            Type 'TreeNodeProps<DataNode>' is not assignable to type 'AntdTreeNodeAttribute'.
              Types of property 'eventKey' are incompatible.
                Type 'Key | undefined' is not assignable to type 'string'.
                  Type 'undefined' is not assignable to type 'string'.

86 export interface TreeProps<T extends BasicDataNode = DataNode> extends Omit<RcTreeProps<T>, 'prefixCls' | 'showLine' | 'direction' | 'draggable'> {
                    ~~~~~~~~~

In my package.json

{ 
         "main": "dist/index.js",
         "typings": "dist/index.d.ts",
          "dependencies": {
         "@babel/polyfill": "^7.12.1",
         "@testing-library/jest-dom": "^5.16.4",
         "@testing-library/react": "^13.3.0",
         "@testing-library/user-event": "^13.5.0",
         "@types/jest": "^27.5.2",
         "@types/node": "^16.11.41",
         "@types/react": "^18.0.14",
         "@types/react-dom": "^18.0.5",
         "antd": "^4.16.0",
         "react": "^18.2.0",
         "react-dom": "^18.2.0",
         "react-scripts": "5.0.1",
         "styled-components": "^5.3.5",
         "ts-loader": "^9.3.0",
         "typescript": "^4.7.3",
         "web-vitals": "^2.1.4",
         "webpack": "^5.73.0",
         "webpack-cli": "^4.10.0"
       },
       "scripts": {
         "start": "react-scripts start",
         "emit-types": "tsc",
         "emit": "tsc --outDir dist --declaration --emitDeclarationOnly",
         "build": "babel src/lib --out-dir dist --extensions '.ts,.tsx' && npm run emit-types && NODE_ENV=production webpack",
         "test": "react-scripts test",
         "eject": "react-scripts eject"
       },
     }

error_image

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月牙弯弯 2025-02-15 19:46:41

我只是遇到了同样的问题,

skipLibCheck:true

在我的tsconfig.json中

添加了我希望您已经解决的问题,但如果其他人面临同一问题,我正在分享我的解决方式,它可能会有所帮助

I've just had the same issue, adding

skipLibCheck:true

in my tsconfig.json solved the issue

I hope you fixed you issue already but in case someone else is facing the same issue, i'm sharing how i solved it, it might help

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文