相关疑难解决方法(0)

在Typescript中使用样式化的组件,prop不存在吗?

这是我的样式化组件。

import * as React from 'react';
import styled from 'styled-components';
import { ComponentChildren } from 'app-types';

interface Props {
    children: ComponentChildren;
    emphasized: boolean;
}

const HeadingStyled = styled.h2`
    ${props => props.emphasized && css`
        display: inline;
        padding-top: 10px;
        padding-right: 30px;
  `}
`;

const Heading = (props: Props) => (
    <HeadingStyled>
        {props.children}
    </HeadingStyled>
);

export default Heading;
Run Code Online (Sandbox Code Playgroud)

我收到以下警告:

  • Property 'emphasized' does not exist on type 'ThemedStyledProps<DetailedHTMLProps<HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, any>'.
  • Cannot find name 'css'. Did you mean 'CSS'?

我该如何工作?

typescript reactjs styled-components

13
推荐指数
3
解决办法
7775
查看次数

标签 统计

reactjs ×1

styled-components ×1

typescript ×1