Allow specifying void for component state type parameter. (#8673)

* Allow specifying `void` for component state type parameter.

Per comments on https://github.com/DefinitelyTyped/DefinitelyTyped/pull/8543,
the type parameter for component state was changed to `{}` from `any` for
increased type safety, but prevents specifying (non-functional) stateless
components without having empty state parameters, which seems messy. This
changes the type to `{} | void` to allow this while staying stricter than
`any`.

* Make react tests a bit more strict.

* Rename State -> ComponentState to make it a bit more explicit.
This commit is contained in:
Sean Kelley
2016-04-13 00:40:40 +09:00
committed by Masahiro Wakame
parent 151dc309c9
commit b9642fb8ac
3 changed files with 29 additions and 22 deletions
+4 -4
View File
@@ -18,14 +18,14 @@ declare namespace __React {
element: SFCElement<P>,
container: Element,
callback?: () => any): void;
function render<P, T extends Component<P, {}>>(
function render<P, T extends Component<P, ComponentState>>(
element: CElement<P, T>,
container: Element,
callback?: (component: T) => any): T;
function render<P>(
element: ReactElement<P>,
container: Element,
callback?: (component?: Component<P, {}> | Element) => any): Component<P, {}> | Element | void;
callback?: (component?: Component<P, ComponentState> | Element) => any): Component<P, ComponentState> | Element | void;
function unmountComponentAtNode(container: Element): boolean;
@@ -40,7 +40,7 @@ declare namespace __React {
element: DOMElement<P, T>,
container: Element,
callback?: (element: T) => any): T;
function unstable_renderSubtreeIntoContainer<P, T extends Component<P, {}>>(
function unstable_renderSubtreeIntoContainer<P, T extends Component<P, ComponentState>>(
parentComponent: Component<any, any>,
element: CElement<P, T>,
container: Element,
@@ -54,7 +54,7 @@ declare namespace __React {
parentComponent: Component<any, any>,
element: ReactElement<P>,
container: Element,
callback?: (component?: Component<P, {}> | Element) => any): Component<P, {}> | Element | void;
callback?: (component?: Component<P, ComponentState> | Element) => any): Component<P, ComponentState> | Element | void;
}
namespace __DOMServer {