mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 21:00:01 +08:00
Make component constructor props non-optional
This commit is contained in:
10
types/react/index.d.ts
vendored
10
types/react/index.d.ts
vendored
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user