小编Sam*_*tro的帖子

如何用样式化组件和TypeScript来包装Ant Design?

我想用样式化组件来包装我的蚂蚁设计组件,我知道这是可能的(https://gist.github.com/samuelcastro/0ff7db4fd54ce2b80cd1c34a85b40c08),但是我在用TypeScript做同样的事情时遇到了麻烦。

这是我到目前为止的内容:

import { Button as AntButton } from 'antd';
import { ButtonProps } from 'antd/lib/button/button';
import styledComponents from 'styled-components';

interface IButtonProps extends ButtonProps {
   customProp: string;
}

export const Button = styledComponents<IButtonProps>(AntButton)`
  // any custom style here
`;
Run Code Online (Sandbox Code Playgroud)

如您所见as any,为了使它起作用,我正在定义ant-design按钮,否则我得到一些不兼容的类型,例如:

Argument of type 'typeof Button' is not assignable to parameter of
type 'ComponentType<IButtonProps>'.

Type 'typeof Button' is not assignable to type
'StatelessComponent<IButtonProps>'.

Types of property 'propTypes' are incompatible.

 Property 'customProp' is missing in type '{ …
Run Code Online (Sandbox Code Playgroud)

typescript styled-components antd

7
推荐指数
4
解决办法
6193
查看次数

标签 统计

antd ×1

styled-components ×1

typescript ×1