Merge pull request #14424 from Strate/patch-2

react: make defaultProps Partial<P>
This commit is contained in:
Arthur Ozga
2017-02-10 14:22:28 -08:00
committed by GitHub
2 changed files with 17 additions and 2 deletions

4
react/index.d.ts vendored
View File

@@ -207,7 +207,7 @@ declare namespace React {
(props: P & { children?: ReactNode }, context?: any): ReactElement<any>;
propTypes?: ValidationMap<P>;
contextTypes?: ValidationMap<any>;
defaultProps?: P;
defaultProps?: Partial<P>;
displayName?: string;
}
@@ -216,7 +216,7 @@ declare namespace React {
propTypes?: ValidationMap<P>;
contextTypes?: ValidationMap<any>;
childContextTypes?: ValidationMap<any>;
defaultProps?: P;
defaultProps?: Partial<P>;
displayName?: string;
}

View File

@@ -689,3 +689,18 @@ type InputChangeEvent = React.ChangeEvent<HTMLInputElement>;
type InputFormEvent = React.FormEvent<HTMLInputElement>;
const changeEvent:InputChangeEvent = undefined as any;
const formEvent:InputFormEvent = changeEvent;
// defaultProps should be optional of props
{
interface ComponentProps {
prop1: string;
prop2: string;
prop3?: string;
}
class ComponentWithDefaultProps extends React.Component<ComponentProps, void> {
static defaultProps = {
prop3: "default value",
};
}
const VariableWithAClass: React.ComponentClass<ComponentProps> = ComponentWithDefaultProps;
}