【发布时间】:2021-06-18 01:48:15
【问题描述】:
我正在尝试将样式化的基础扩展到其他样式化的组件,但我收到了打字稿错误。我已经能够在纯 javascript 中做到这一点,我无法在 typescript 中做同样的事情
基础文件 _Modal.ts
import styled from 'styled-components/macro'
interface I_Modal {
'background-color': string
'min-height': string
'min-width': string
}
const _modal = styled.div<I_Modal>`
background-color: ${props => props['background-color'] ? props['background-color'] : props.theme.colors.baseColor};
min-height: ${props => props['min-height'] ? props['min-height'] : '300px'};
min-width: ${props => props['min-width'] ? props['min-width'] : '200px'}
`
export default _modal
文件我正在尝试将样式扩展到 registerModal.ts
import styled from 'styled-components/macro'
import _modal from './_modal'
export const RegisterModal = styled(_modal)`
background-color: purple;
height: 300px;
width: 200px;
`
VSCode 中的一切都说它很好,只是编译不正确 image of error
【问题讨论】:
标签: reactjs typescript styled-components