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
+6
View File
@@ -138,6 +138,8 @@ class ModernComponent extends React.Component<Props, State>
}
}
class ModernComponentNoState extends React.Component<Props, void> {}
interface SCProps {
foo?: number;
}
@@ -182,6 +184,8 @@ var domFactoryElement: React.DOMElement<React.DOMAttributes, Element> =
// React.createElement
var element: React.CElement<Props, ModernComponent> =
React.createElement(ModernComponent, props);
var elementNoState: React.CElement<Props, ModernComponentNoState> =
React.createElement(ModernComponentNoState, props);
var statelessElement: React.SFCElement<SCProps> =
React.createElement(StatelessComponent, props);
var classicElement: React.ClassicElement<Props> =
@@ -216,6 +220,8 @@ var clonedDOMElement: React.ReactHTMLElement<HTMLDivElement> =
// React.render
var component: ModernComponent =
ReactDOM.render(element, container);
var componentNoState: ModernComponentNoState =
ReactDOM.render(elementNoState, container);
var classicComponent: React.ClassicComponent<Props, any> =
ReactDOM.render(classicElement, container);
var domComponent: Element =