Make component constructor props non-optional

This commit is contained in:
Tom Crockett
2017-10-24 17:33:43 -07:00
parent b7e43ef2bb
commit e9f19bb876
2 changed files with 8 additions and 8 deletions

View File

@@ -277,7 +277,7 @@ declare namespace React {
// tslint:disable-next-line:no-empty-interface
interface Component<P = {}, S = {}> extends ComponentLifecycle<P, S> { }
class Component<P, S> {
constructor(props?: P, context?: any);
constructor(props: P, context?: any);
// Disabling unified-signatures to have separate overloads. It's easier to understand this way.
// tslint:disable:unified-signatures
@@ -327,7 +327,7 @@ declare namespace React {
}
interface ComponentClass<P = {}> {
new (props?: P, context?: any): Component<P, ComponentState>;
new (props: P, context?: any): Component<P, ComponentState>;
propTypes?: ValidationMap<P>;
contextTypes?: ValidationMap<any>;
childContextTypes?: ValidationMap<any>;
@@ -336,7 +336,7 @@ declare namespace React {
}
interface ClassicComponentClass<P = {}> extends ComponentClass<P> {
new (props?: P, context?: any): ClassicComponent<P, ComponentState>;
new (props: P, context?: any): ClassicComponent<P, ComponentState>;
getDefaultProps?(): P;
}
@@ -347,8 +347,8 @@ declare namespace React {
*/
type ClassType<P, T extends Component<P, ComponentState>, C extends ComponentClass<P>> =
C &
(new (props?: P, context?: any) => T) &
(new (props?: P, context?: any) => { props: P });
(new (props: P, context?: any) => T) &
(new (props: P, context?: any) => { props: P });
//
// Component Specs and Lifecycle

View File

@@ -262,7 +262,7 @@ class RefComponent extends React.Component<RCProps> {
}
}
let componentRef: RefComponent | null = new RefComponent();
let componentRef: RefComponent | null = new RefComponent({});
RefComponent.create({ ref: "componentRef" });
// type of c should be inferred
RefComponent.create({ ref: c => componentRef = c });
@@ -609,8 +609,8 @@ if (TestUtils.isElementOfType(emptyElement2, StatelessComponent)) {
if (TestUtils.isDOMComponent(container)) {
container.getAttribute("className");
} else if (TestUtils.isCompositeComponent(new ModernComponent())) {
new ModernComponent().props;
} else if (TestUtils.isCompositeComponent(new ModernComponent({ hello: 'hi', foo: 3 }))) {
new ModernComponent({ hello: 'hi', foo: 3 }).props;
}
//