Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

编写组件说明文件遇到的坑 #38

Open
ChenPt opened this issue Mar 19, 2020 · 0 comments
Open

编写组件说明文件遇到的坑 #38

ChenPt opened this issue Mar 19, 2020 · 0 comments
Labels
TypeScript TypeScript 相关

Comments

@ChenPt
Copy link
Owner

ChenPt commented Mar 19, 2020

想要支持组件类作为参数传给组件,一开始编写的是

// index.d.ts
export interface IProps {
  CheckBox?: CheckBox
}

declare class CheckBox extends React.Component<ChexkBoxProps> {
  render(): JSX.Element;
}

// index.tsx
const { CheckBox } = this.props;
<CheckBox />
引用时会提示 `JSX元素类型'CheckBox'没有任何构造或调用签名”`

查询资料得知 组件类作为参数需要如下写法

declare class CheckBox extends React.Component<ChexkBoxProps> {
  render(): JSX.Element;
}

export type CheckBoxComp = CheckBox<ChexkBoxProps>;

export interface IProps {
  CheckBox?: CheckBoxComp; // 将组件类作为参数
}
@ChenPt ChenPt added the TypeScript TypeScript 相关 label Mar 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TypeScript TypeScript 相关
Projects
None yet
Development

No branches or pull requests

1 participant