简体   繁体   English

打字稿说我用样式组件包装的组件上不存在道具

[英]Typescript says a prop does not exist on a component I wrapped with styled-components

I am using semantic-ui-react and along with styled-components.我正在使用semantic-ui-react 和styled-components。 I am wrapping the Tab component with styled-components to customize its look.我正在用 styled-components 包装 Tab 组件以自定义其外观。 Here is that code这是那个代码

const CustomTab = styled(Tab)<{props: TabProps}>`
    flex: 1;
    display: flex;
    margin-top: 10px;
    flex-direction: column;
`;

As you can see I am trying to specify that the props for CustomTab will be the same props as the Tab component.如您所见,我试图指定CustomTab的道具与Tab组件的道具相同。 I did this based on this answer.我是根据这个答案做的。

The problem is that typescript still seems to think that Menu props does not exits on my CustomTab component.问题是打字稿似乎仍然认为Menu道具不会在我的CustomTab组件上退出。

Where am I going wrong?我哪里错了?

Try const CustomTab = styled(Tab)<TabProps>试试const CustomTab = styled(Tab)<TabProps>

You basically defined your props as an object that looks like this: {props: {TabProps}}您基本上将道具定义为一个如下所示的对象: {props: {TabProps}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM