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

Form.create() break defaultProps in typescript. #16095

Closed
1 task done
fwh1990 opened this issue Apr 15, 2019 · 10 comments · Fixed by #16126
Closed
1 task done

Form.create() break defaultProps in typescript. #16095

fwh1990 opened this issue Apr 15, 2019 · 10 comments · Fixed by #16126

Comments

@fwh1990
Copy link

fwh1990 commented Apr 15, 2019

  • I have searched the issues of this repository and believe that this is not a duplicate.

Reproduction link

http://www.baidu.com

Steps to reproduce

interface OwnProps {
  aa: string;
}

type Props = OwnProps & FormComponentProps;

class HiMan extends React.Component<Props> {
  static defaultProps: Partial<Props> {
    aa: 'default value',
  }

  render() {
    return 'ok';
  }
}

export default Form.create()(HiMan);

What is expected?

Call the component exclude default props

render() {
  return <HiMan />;
}

What is actually happening?

prop aa is required when calling.

render() {
  return <HiMan aa="Required now..." />;
}
Environment Info
antd 3.16.3
React 16.8.6
System macos 10.14
Browser chrome 74

You can look up how react-connect hold defaultProps.

@afc163
Copy link
Member

afc163 commented Apr 15, 2019

https://ant.design/components/form/#Using-in-TypeScript

An enterprise-class UI design language and React-based implementation with a set of high-quality React components, one of best React UI library for enterprises

@afc163 afc163 closed this as completed Apr 15, 2019
@fwh1990
Copy link
Author

fwh1990 commented Apr 16, 2019

https://ant.design/components/form/#Using-in-TypeScript

**Ant Design - A UI Design Language**An enterprise-class UI design language and React-based implementation with a set of high-quality React components, one of best React UI library for enterprises

I have changed my code as:

interface Props extends FormComponentProps {
  aa: string;
}

class HiMan extends React.Component<Props> {
  static defaultProps: Partial<Props> {
    aa: 'default value',
  }

  render() {
    return 'ok';
  }
}

export default Form.create<Props>()(HiMan);

And nothing changed.

render() {
  return <HiMan aa="Required also..." />;
}

So, you shouldn't close this issue.

An enterprise-class UI design language and React-based implementation with a set of high-quality React components, one of best React UI library for enterprises

@fwh1990
Copy link
Author

fwh1990 commented Apr 16, 2019

Had you tried defaultProps ever? @afc163

@fwh1990
Copy link
Author

fwh1990 commented Apr 16, 2019

And HOC connect can keep defaultProps well.

import { connect } from 'react-redux'; 

interface Props {
  aa: string;
}

class HiMan extends React.Component<Props> {
  static defaultProps: Partial<Props> {
    aa: 'default value',
  }

  render() {
    return 'ok';
  }
}

export default connect()(HiMan);
render() {
  return <HiMan />;
}

@afc163 afc163 reopened this Apr 16, 2019
@ztplz
Copy link
Contributor

ztplz commented Apr 16, 2019

image
Any repo ?

@afc163 afc163 added the 🤔 Need Reproduce We cannot reproduce your problem label Apr 16, 2019
@ant-design-bot
Copy link
Contributor

ant-design-bot commented Apr 16, 2019

Hello @fwh1990. Please provide a online reproduction by forking this link https://u.ant.design/codesandbox-repro or a minimal GitHub repository. Issues labeled by Need Reproduce will be closed if no activities in 7 days.

你好 @fwh1990, 我们需要你提供一个在线的重现实例以便于我们帮你排查问题。你可以通过点击 此处 创建一个 codesandbox 或者提供一个最小化的 GitHub 仓库。7 天内未跟进的 issue 将会被自动关闭。

@zombieJ zombieJ added 👷🏻‍♂️ Someone working on it and removed 🤔 Need Reproduce We cannot reproduce your problem labels Apr 16, 2019
@zombieJ zombieJ assigned zombieJ and unassigned yesmeck Apr 16, 2019
@fwh1990
Copy link
Author

fwh1990 commented Apr 23, 2019

The problem of defaultProps has been solved, but something get wrong.

// File: node_modules/antd/lib/form/interface.d.ts

export declare type FormWrappedProps<TOwnProps extends FormComponentProps> = <C extends React.ComponentType>(component: C) => ConnectedComponentClass<C, Omit<TOwnProps, keyof FormComponentProps>>;

I guess you have missed TOwnProps.

I mean, the keyword <C extends React.ComponentType> should be written as <C extends React.ComponentType<TOwnProps>>. Otherwise, some errors will be reported when I export component.

image

DF0BFC19-3754-4469-9C56-33E6D3FE6C72

@zombieJ

@zombieJ
Copy link
Member

zombieJ commented Apr 23, 2019

Yes. Added in new patch: da9cef9#diff-6674060020d469d3799f602cd77df0cdR26

@Polqk
Copy link

Polqk commented Sep 25, 2019

Casting Form.create with Component Props works form me

image

@papasavvasn
Copy link

papasavvasn commented Dec 5, 2019

The solution of @Polqk (#16095) worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants