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:
Nathan Shively-Sanders
2017-05-24 07:46:27 -07:00
parent e63f331400
commit dde2a7a3ba

View File

@@ -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;