问题描述
我喜欢使用 BEM 概念。我想将 BEM 应用于样式组件,我在下面找到了解决方案。
const Something = styled.div``;
const SomeElement = styled.div``;
Something.someElement = SomeElement;
export default Something;
但是使用 typescript 时,会出现 StyledComponent
没有 SomeElement
属性的错误。为了解决这个问题,一些 stackoverflow 答案提出了一个解决方案,下面的代码是我应用该解决方案的内容。
import styled,{ DefaultTheme,StyledComponentBase } from 'styled-components';
import Description from './Description';
import Sup from './Sup';
interface TitleBlock extends StyledComponentBase<'h1',DefaultTheme> {
Sup?: typeof Sup;
Description?: typeof Description;
}
const Title: TitleBlock = styled.h1`
/* styling here */
`;
Title.Sup = Sup;
Title.Description = Description;
export default Title;
我的问题是,有没有更好的方法来定义 TitleBlock
元素?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)