mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-06-28 14:20:12 +00:00
Change react's ComponentLifecycle to class
ComponentLifecycle is intended to provide some methods to Component subclasses and enforce that overrides of those methods are correct in those same subclasses. However, it does neither of these things as an interface that Component `implements`. It just checks that Component has all the required methods of ComponentLifecycle. Since there are no required methods, the `implements` check passes. And since Component doesn't actually *implement* any of the methods, its subclasses don't get them by default, and their 'overrides' are not checked for correctness. Changing ComponentLifecycle to a class fixes both of these problems.
This commit is contained in:
4
types/react/index.d.ts
vendored
4
types/react/index.d.ts
vendored
@@ -178,7 +178,7 @@ declare namespace React {
|
||||
type ReactInstance = Component<any, any> | Element;
|
||||
|
||||
// Base component for plain JS classes
|
||||
class Component<P, S> implements ComponentLifecycle<P, S> {
|
||||
class Component<P, S> extends ComponentLifecycle<P, S> {
|
||||
constructor(props?: P, context?: any);
|
||||
setState<K extends keyof S>(f: (prevState: S, props: P) => Pick<S, K>, callback?: () => any): void;
|
||||
setState<K extends keyof S>(state: Pick<S, K>, callback?: () => any): void;
|
||||
@@ -251,7 +251,7 @@ declare namespace React {
|
||||
// Component Specs and Lifecycle
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
interface ComponentLifecycle<P, S> {
|
||||
class ComponentLifecycle<P, S> {
|
||||
componentWillMount?(): void;
|
||||
componentDidMount?(): void;
|
||||
componentWillReceiveProps?(nextProps: Readonly<P>, nextContext: any): void;
|
||||
|
||||
Reference in New Issue
Block a user