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
fwh1990 opened this issue Apr 15, 2019 · 8 comments

Comments

Projects
None yet
6 participants
@fwh1990
Copy link

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

This comment has been minimized.

Copy link
Member

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 Apr 15, 2019

@fwh1990

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Author

commented Apr 16, 2019

Had you tried defaultProps ever? @afc163

@fwh1990

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Collaborator

commented Apr 16, 2019

image
Any repo ?

@ant-design-bot

This comment has been minimized.

Copy link

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 将会被自动关闭。

@fwh1990

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Member

commented Apr 23, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.