mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
react: change default type value of snapshot to any (#24987)
* Add getSnapshotBeforeUpdate test for React.createElement * Add test for using component with new lifecycles * Add test for pure component with new lifecycle methods * Chage react snapshot SS to default to any
This commit is contained in:
committed by
Ryan Cavanaugh
parent
f0bf0a7cef
commit
c9de295a09
Vendored
+2
-2
@@ -278,7 +278,7 @@ declare namespace React {
|
||||
|
||||
// Base component for plain JS classes
|
||||
// tslint:disable-next-line:no-empty-interface
|
||||
interface Component<P = {}, S = {}, SS = never> extends ComponentLifecycle<P, S, SS> { }
|
||||
interface Component<P = {}, S = {}, SS = any> extends ComponentLifecycle<P, S, SS> { }
|
||||
class Component<P, S> {
|
||||
constructor(props: P, context?: any);
|
||||
|
||||
@@ -306,7 +306,7 @@ declare namespace React {
|
||||
};
|
||||
}
|
||||
|
||||
class PureComponent<P = {}, S = {}> extends Component<P, S> { }
|
||||
class PureComponent<P = {}, S = {}, SS = any> extends Component<P, S, SS> { }
|
||||
|
||||
interface ClassicComponent<P = {}, S = {}> extends Component<P, S> {
|
||||
replaceState(nextState: S, callback?: () => void): void;
|
||||
|
||||
@@ -25,6 +25,10 @@ interface State {
|
||||
seconds?: number;
|
||||
}
|
||||
|
||||
interface Snapshot {
|
||||
baz: string;
|
||||
}
|
||||
|
||||
interface Context {
|
||||
someValue?: string;
|
||||
}
|
||||
@@ -51,7 +55,7 @@ declare const container: Element;
|
||||
// Top-Level API
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
class ModernComponent extends React.Component<Props, State>
|
||||
class ModernComponent extends React.Component<Props, State, Snapshot>
|
||||
implements MyComponent, React.ChildContextProvider<ChildContext> {
|
||||
static propTypes: React.ValidationMap<Props> = {
|
||||
foo: PropTypes.number
|
||||
@@ -103,6 +107,14 @@ class ModernComponent extends React.Component<Props, State>
|
||||
shouldComponentUpdate(nextProps: Props, nextState: State, nextContext: any): boolean {
|
||||
return shallowCompare(this, nextProps, nextState);
|
||||
}
|
||||
|
||||
getSnapshotBeforeUpdate(prevProps: Readonly<Props>) {
|
||||
return { baz: `${prevProps.foo}baz` };
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps: Readonly<Props>, prevState: Readonly<State>, snapshot: Snapshot) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
class ModernComponentArrayRender extends React.Component<Props> {
|
||||
|
||||
@@ -153,6 +153,26 @@ class ComponentWithNewLifecycles extends React.Component<NewProps, NewState, { b
|
||||
return this.state.bar;
|
||||
}
|
||||
}
|
||||
<ComponentWithNewLifecycles foo="bar" />;
|
||||
|
||||
class PureComponentWithNewLifecycles extends React.PureComponent<NewProps, NewState, { baz: string }> {
|
||||
static getDerivedStateFromProps: React.GetDerivedStateFromProps<NewProps, NewState> = (nextProps) => {
|
||||
return { bar: `${nextProps.foo}bar` };
|
||||
}
|
||||
|
||||
getSnapshotBeforeUpdate(prevProps: Readonly<NewProps>) {
|
||||
return { baz: `${prevProps.foo}baz` };
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps: Readonly<NewProps>, prevState: Readonly<NewState>, snapshot: { baz: string }) {
|
||||
return;
|
||||
}
|
||||
|
||||
render() {
|
||||
return this.state.bar;
|
||||
}
|
||||
}
|
||||
<PureComponentWithNewLifecycles foo="bar" />;
|
||||
|
||||
class ComponentWithLargeState extends React.Component<{}, Record<'a'|'b'|'c', string>> {
|
||||
static getDerivedStateFromProps: React.GetDerivedStateFromProps<{}, Record<'a'|'b'|'c', string>> = () => {
|
||||
|
||||
Reference in New Issue
Block a user