-
Notifications
You must be signed in to change notification settings - Fork 30.5k
[react] Allow to initialize state in constructor #26912
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -306,7 +306,7 @@ declare namespace React { | |
| // In the future, if we can define its call signature conditionally | ||
| // on the existence of `children` in `P`, then we should remove this. | ||
| readonly props: Readonly<{ children?: ReactNode }> & Readonly<P>; | ||
| readonly state: null | Readonly<S>; | ||
| state: null | Readonly<S>; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am too late in making this comment, but I don't see why removing this The
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, ideally, it would be nice to be able to use conditional types to make
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are partially correct. Readonly properties are writable in the constructors of the the class that defines the property. Not in subclasses. But it is completely valid and recommended to do so in React. See microsoft/TypeScript#25134 (comment) for more details. I would like to emphasize that union with
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what @magnetnation said.
That wont help, when you'll define state on your class via class property, it will override Base class
yeah that's right, also props should be |
||
| /** | ||
| * @deprecated | ||
| * https://reactjs.org/docs/legacy-context.html | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not a rollback, you need to remove null from the definition as well
otherwise there will be still errors: