antd,`tsc`获取错误:接口' treeprops< t>'错误地扩展了接口< treeprops< t>
我想创建在项目内使用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"
},
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只是遇到了同样的问题,
在我的tsconfig.json中
添加了我希望您已经解决的问题,但如果其他人面临同一问题,我正在分享我的解决方式,它可能会有所帮助
I've just had the same issue, adding
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