-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Default initializers doesn't work for defaultProps #32402
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
Comments
The documentation you linked refers to a static
Stackblitz example: https://stackblitz.com/edit/react-ts-bsvjqe?file=index.tsx (ignore the errors, the used TypeScript version is old) |
It has this section
|
This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
@RyanCavanaugh Could you elaborate what is working as intended? And what this line means
|
Your function has two conflicting pieces of information:
TypeScript says that parameter type annotations always win in this situation. |
@RyanCavanaugh Thank. So for functional component I need to use defaultProps.
and I can use But I don't understand what is the point of this example from release notes
It doesn't do anything useful, because I need to use |
@RyanCavanaugh any thoughts? |
default initializers defaultProps
Code
Expected behavior:
According to https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-0.html#caveats
it shouldn't have error
Actual behavior:
Has error
Playground Link:
http://www.typescriptlang.org/play/?jsx=2#code/PTAEGcFMBdQKQMoA1TQPagEQCVIEMBjaTUNAJywAUzIoyA3STAWACg2RQAzPAa0lAAjAJYA7ACZiA5uDbjIBADZ4aoUXgC2tAA6EBuQrADebUNwCuoosLSjQBGnmiQAooshbR0ABQBKAFygeKIAngDcbAC+bGxizmQ8BALUaNrgoCasZupageDQZNJRMaxclta2oADiNDDeRmqaAgC8WADu5IriJJGBKWm+GaZmoDTQ5mR2AOQAEpCKimhTZgDUjVoAdOgAqtrakGQAwnhQfgCEEazR7KwEtvmg4mgaoK0APDWQMKDAAHxAA
There is a workaround
But I would prefer to use default initializers
The text was updated successfully, but these errors were encountered: