简体   繁体   English

子组件的类型定义

[英]Type Definitions for sub components

I have defined sub-components to my styled component, and am trying to provide type definitions for it - TSC complains 'Property 'PrimaryText' does not exist on type 'StyledComponentClass'. 我已经为样式化的组件定义了子组件,并试图为其提供类型定义-TSC抱怨'StyledComponentClass'类型上不存在'Property'PrimaryText'。 Similarly for 'SubText'. 对于“ SubText”也是如此。

export const Tab = styled(NavLink)`
    border: 1px solid rgba(0, 119, 204, 0.5);
    box-shadow: 0 0 8px 0 rgba(0, 0, 0, 0.08), 0 2px 15px 0 rgba(0, 0, 0, 0.08);
    box-sizing: border-box;
    height: 60px;
    min-width: 125px;
    padding: 10px 15px;
    cursor: pointer;
`;

Tab.PrimaryText = styled(Box)`
    height: 22px;
    color: #3d464d;
    font-size: 16px;
    font-weight: 600;
    line-height: 22px;
`;

Tab.SubText = styled(Box)`
    height: 15px;
    color: #525d66;
    font-size: 11px;
    line-height: 15px;
`;

How do I go about specifying the types? 如何指定类型? Looked around a lot. 环顾四周。 There's hardly any reference. 几乎没有参考。

What are you trying to achieve by doing this? 您正在尝试通过此方法实现什么? There are some convoluted ways you could use to create a merged type but it really doesn't seem worth it. 您可以使用一些复杂的方法来创建合并类型,但这似乎并不值得。

Would something like this not be an option? 这样的事情不是一种选择吗? The only difference being the usage of the Tab style is now Tab.Main (or whatever you call it) instead. 唯一的区别是现在使用Tab.Main (或任何您称呼的名称)代替了Tab样式的用法。

export const Tab = {
  Main: styled(NavLink)`
    border: 1px solid rgba(0, 119, 204, 0.5);
    box-shadow: 0 0 8px 0 rgba(0, 0, 0, 0.08), 0 2px 15px 0 rgba(0, 0, 0, 0.08);
    box-sizing: border-box;
    height: 60px;
    min-width: 125px;
    padding: 10px 15px;
    cursor: pointer;
  `,
  PrimaryText: styled(Box)`
    height: 22px;
    color: #3d464d;
    font-size: 16px;
    font-weight: 600;
    line-height: 22px;
  `,
  SubText: styled(Box)`
    height: 15px;
    color: #525d66;
    font-size: 11px;
    line-height: 15px;
  `,
};

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

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