question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Form.create() break defaultProps in typescript.

See original GitHub issue
  • 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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
fwh1990commented, 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

3reactions
Polqkcommented, Sep 25, 2019

Casting Form.create with Component Props works form me

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Typing defaultProps - React TypeScript Cheatsheets
The consensus is to use object default values. Function Components: type GreetProps = { age ...
Read more >
TypeScript doesn't see defaultProps for functional components
This is a bug on 3.1. The code below works on 3.2 (at moment unreleased, you can install using npm install typescript@next
Read more >
Default Props in React/TS - Part Deux - DEV Community ‍ ‍
I'm creating functional components (as opposed to class-based components). · Those functional components must be able to accept a single object ...
Read more >
React: Everything about Default Props | by Chidume Nnamdi
markup (delivered by render() ). All these combined together create a UI widget. So- that was fun, right? but you kinds knew all...
Read more >
Documentation - TypeScript 3.0
Specifying these dependencies makes it easier to split your code into smaller ... TypeScript 3.0 also introduces a new mode for tsc, the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found