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
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:
- Created 4 years ago
- Comments:10 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The problem of defaultProps has been solved, but something get wrong.
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.@zombieJ
Casting Form.create with Component Props works form me