Commit
- fix(react): remove failing expectation on TS 2.6 - chore(react): add myself to contributors
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
// Ferdy Budhidharma <https://github.com/ferdaber> | ||
// Johann Rakotoharisoa <https://github.com/jrakotoharisoa> | ||
// Olivier Pascal <https://github.com/pascaloliv> | ||
// Martin Hochel <https://github.com/hotell> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
// TypeScript Version: 2.6 | ||
|
||
|
@@ -281,13 +282,18 @@ declare namespace React { | |
// tslint:disable-next-line:no-empty-interface | ||
interface Component<P = {}, S = {}, SS = any> extends ComponentLifecycle<P, S, SS> { } | ||
class Component<P, S> { | ||
constructor(props: Readonly<P>); | ||
/** | ||
* @deprecated | ||
* https://reactjs.org/docs/legacy-context.html | ||
*/ | ||
constructor(props: P, context?: any); | ||
|
||
// We MUST keep setState() as a unified signature because it allows proper checking of the method return type. | ||
// See: https://github.com/DefinitelyTyped/DefinitelyTyped/issues/18365#issuecomment-351013257 | ||
// Also, the ` | S` allows intellisense to not be dumbisense | ||
setState<K extends keyof S>( | ||
state: ((prevState: Readonly<S>, props: P) => (Pick<S, K> | S | null)) | (Pick<S, K> | S | null), | ||
state: ((prevState: Readonly<S>, props: Readonly<P>) => (Pick<S, K> | S | null)) | (Pick<S, K> | S | null), | ||
callback?: () => void | ||
): void; | ||
|
||
|
@@ -299,9 +305,17 @@ declare namespace React { | |
// always pass children as variadic arguments to `createElement`. | ||
// In the future, if we can define its call signature conditionally | ||
// on the existence of `children` in `P`, then we should remove this. | ||
props: Readonly<{ children?: ReactNode }> & Readonly<P>; | ||
state: Readonly<S>; | ||
readonly props: Readonly<{ children?: ReactNode }> & Readonly<P>; | ||
readonly state: null | Readonly<S>; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Rycochet
Contributor
|
||
/** | ||
* @deprecated | ||
* https://reactjs.org/docs/legacy-context.html | ||
*/ | ||
context: any; | ||
/** | ||
* @deprecated | ||
* https://reactjs.org/docs/refs-and-the-dom.html#legacy-api-string-refs | ||
*/ | ||
refs: { | ||
[key: string]: ReactInstance | ||
}; | ||
|
10 comments
on commit 542f3c0
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.
@Hotell I don't understand. This change breaks a LOT of my code. Why do we have to specify state
as an instance variable explicitly now?
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.
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.
Shouldn't such a big change be bumping the major version number? I assume a lot of old code will break due to this change if they have @types/react
as ^16.x.x
in their package.json.
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.
@pelotom Tom, if you have time, could you validate this PR and see if specifying state as an instance variable explicitly here is intended? If so, from your knowledge, why?
Thanks a lot!
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.
Forcing the state to be readonly is defintelly a breaking change, especially considering the fact that the react documentation is showcasing an initialization in the class constructor.
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.
it makes more sense that you define a special type in Constructor.
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 change also broke my app so that's a bit annoying. But anyway, do you have an idea how to fix that? I don't feel confident using setState in the constructor as it's explicitly forbidden by the react documentation.
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.
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.
Yes, of course, that's what I do, but if I do that, I get this error now:
TS2540: Cannot assign to 'state' because it is a constant or a read-only property.
Here is my code BTW:
constructor(props: TableProps) {
super(props);
this.state = {
nextItemToAddPosition: 0,
};
}
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.
Ok, just found the PR with explained workaround: #26813
Why State can always be null ?! this is a bad regression