From dde2a7a3ba61cdb8ec4bb29f3dc4fd45694911fa Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 24 May 2017 07:46:27 -0700 Subject: [PATCH] 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. --- types/react/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/react/index.d.ts b/types/react/index.d.ts index f2df9c3f69..cdea0f674f 100644 --- a/types/react/index.d.ts +++ b/types/react/index.d.ts @@ -178,7 +178,7 @@ declare namespace React { type ReactInstance = Component | Element; // Base component for plain JS classes - class Component implements ComponentLifecycle { + class Component extends ComponentLifecycle { constructor(props?: P, context?: any); setState(f: (prevState: S, props: P) => Pick, callback?: () => any): void; setState(state: Pick, callback?: () => any): void; @@ -251,7 +251,7 @@ declare namespace React { // Component Specs and Lifecycle // ---------------------------------------------------------------------- - interface ComponentLifecycle { + class ComponentLifecycle { componentWillMount?(): void; componentDidMount?(): void; componentWillReceiveProps?(nextProps: Readonly

, nextContext: any): void;