Reactjs 实现react引导选项卡时出现TypeScript错误
我在创建react应用程序typescript应用程序中实现react引导选项卡时遇到问题。下面是我的代码Reactjs 实现react引导选项卡时出现TypeScript错误,reactjs,twitter-bootstrap,tabs,react-bootstrap,Reactjs,Twitter Bootstrap,Tabs,React Bootstrap,我在创建react应用程序typescript应用程序中实现react引导选项卡时遇到问题。下面是我的代码 import React from "react"; import { Link } from "react-router-dom"; import Tabs from 'react-bootstrap/Tabs'; import Tab from 'react-bootstrap/Tabs'; export function Sonnet(pro
import React from "react";
import { Link } from "react-router-dom";
import Tabs from 'react-bootstrap/Tabs';
import Tab from 'react-bootstrap/Tabs';
export function Sonnet(props: any) {
return (<div>Test</div>);
}
const AddCampaigns: React.FunctionComponent<any> = (props: any) => {
return (
<div className='row'>
<Tabs defaultActiveKey="profile" id="uncontrolled-tab-example">
<Tab eventKey="home" title="Home">
<Sonnet />
</Tab>
<Tab eventKey="profile" title="Profile">
<Sonnet />
</Tab>
<Tab eventKey="contact" title="Contact" disabled>
<Sonnet />
</Tab>
</Tabs>
</div>
);
}
export default AddCampaigns;
从“React”导入React;
从“react router dom”导入{Link};
从“反应引导/选项卡”导入选项卡;
从“反应引导/选项卡”导入选项卡;
导出功能十四行诗(道具:任何){
返回(测试);
}
const AddCampaigns:React.FunctionComponent=(道具:任意)=>{
返回(
);
}
导出默认活动;
以下是错误消息:
TypeScript error in src/components/templates/tab/index.tsx(14,22):
No overload matches this call.
Overload 1 of 2, '(props: Readonly<ReplaceProps<BsPrefixComponentClass<"div", NavProps>, BsPrefixProps<BsPrefixComponentClass<"div", NavProps>> & TabsProps>>): Tabs<...>', gave the following error.
Type '{ children: Element; eventKey: string; title: string; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Tabs<BsPrefixComponentClass<"div", NavProps>>> & Readonly<...> & Readonly<...>'.
Property 'eventKey' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Tabs<BsPrefixComponentClass<"div", NavProps>>> & Readonly<...> & Readonly<...>'.
Overload 2 of 2, '(props: ReplaceProps<BsPrefixComponentClass<"div", NavProps>, BsPrefixProps<BsPrefixComponentClass<"div", NavProps>> & TabsProps>, context?: any): Tabs<...>', gave the following error.
Type '{ children: Element; eventKey: string; title: string; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Tabs<BsPrefixComponentClass<"div", NavProps>>> & Readonly<...> & Readonly<...>'.
Property 'eventKey' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<Tabs<BsPrefixComponentClass<"div", NavProps>>> & Readonly<...> & Readonly<...>'. TS2769
src/components/templates/tab/index.tsx中的类型脚本错误(14,22):
没有与此调用匹配的重载。
重载1/2'(道具:只读):选项卡',出现以下错误。
类型“{children:Element;eventKey:string;title:string;}”不可分配给类型“IntrinsicAttributes&IntrinsicClassAttributes&Readonly&Readonly”。
类型“IntrinsicatAttributes&IntrinsicClassAttributes&Readonly&Readonly”上不存在属性“eventKey”。
重载2/2'(props:ReplaceProps,context?:any):Tabs'导致以下错误。
类型“{children:Element;eventKey:string;title:string;}”不可分配给类型“IntrinsicAttributes&IntrinsicClassAttributes&Readonly&Readonly”。
类型“IntrinsicatAttributes&IntrinsicClassAttributes&Readonly&Readonly”上不存在属性“eventKey”。TS2769
有什么办法解决这个问题吗?
谢谢
编辑:在代码中更新正确的代码,前提是您正在从错误目录导入
Tab
组件:react bootstrap/Tabs
,而不是react bootstrap/Tab
:
import Tab from 'react-bootstrap/Tab';
您也可以这样导入它:
import { Tabs, Tab } from "react-bootstrap";
谢谢你,尼古拉!,你节省了我的时间。