mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
[react]: Remove deprecated+removed APIs (#20409)
* create-react-class: add definitions * react-dom-factories: add definitions * create-react-class: add tests, fix errors * react-dom-factories: add tests, fix lint * react: remove previously deprecated APIs * Remove deprecated usages in other definitions * redux-form: disable strictFunctionTypes Changes to react typings revealed errors in redux-form that are present in 'master'. This needs to be handled separately. * Update create-react-class, react-dom-factories author * Avoid importing create-react-class where possible * Move top-level createReactClass tests to create-react-class
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
import * as React from "react";
|
||||
import * as ReactDOM from "react-dom";
|
||||
import * as DOM from "react-dom-factories";
|
||||
import * as createReactClass from "create-react-class";
|
||||
|
||||
interface Props {
|
||||
foo: string;
|
||||
}
|
||||
|
||||
interface State {
|
||||
bar: number;
|
||||
}
|
||||
|
||||
const props: Props & React.ClassAttributes<{}> = {
|
||||
foo: "foo"
|
||||
};
|
||||
|
||||
const container: Element = document.createElement("div");
|
||||
|
||||
//
|
||||
// Top-Level API
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
const ClassicComponent: React.ClassicComponentClass<Props> = createReactClass<Props, State>({
|
||||
childContextTypes: {},
|
||||
componentDidCatch(err, errorInfo) {
|
||||
const msg: string = err.message;
|
||||
const name: string = err.name;
|
||||
const stack: string | undefined = err.stack;
|
||||
const componentStack: string = errorInfo.componentStack;
|
||||
},
|
||||
componentDidMount() {},
|
||||
componentDidUpdate(props, state) {
|
||||
const foo: string = props.foo;
|
||||
const bar: number = state.bar;
|
||||
},
|
||||
componentWillMount() {},
|
||||
componentWillReceiveProps(nextProps) {
|
||||
const oldFoo: string = nextProps.foo;
|
||||
},
|
||||
componentWillUnmount() {},
|
||||
componentWillUpdate(props, state) {
|
||||
const foo: string = props.foo;
|
||||
const bar: number = state.bar;
|
||||
},
|
||||
contextTypes: {},
|
||||
displayName: "Test",
|
||||
getDefaultProps() {
|
||||
return { foo: "f" };
|
||||
},
|
||||
getInitialState() {
|
||||
return { bar: 1 };
|
||||
},
|
||||
mixins: [],
|
||||
propTypes: {},
|
||||
shouldComponentUpdate(this: React.ClassicComponent<Props, State>, nextProps, nextState) {
|
||||
const newFoo: string = nextProps.foo;
|
||||
const newBar: number = nextState.bar;
|
||||
return newFoo !== this.props.foo && newBar !== this.state.bar;
|
||||
},
|
||||
statics: {
|
||||
test: 1
|
||||
},
|
||||
reset() {
|
||||
this.replaceState(this.getInitialState!());
|
||||
},
|
||||
render() {
|
||||
return DOM.div(null,
|
||||
DOM.input({
|
||||
ref: input => this._input = input,
|
||||
value: this.state.bar
|
||||
}));
|
||||
}
|
||||
});
|
||||
|
||||
// React.createFactory
|
||||
const classicFactory: React.ClassicFactory<Props> =
|
||||
React.createFactory(ClassicComponent);
|
||||
const classicFactoryElement: React.ClassicElement<Props> =
|
||||
classicFactory(props);
|
||||
|
||||
// React.createElement
|
||||
const classicElement: React.ClassicElement<Props> = React.createElement(ClassicComponent, props);
|
||||
|
||||
// React.cloneElement
|
||||
const clonedClassicElement: React.ClassicElement<Props> =
|
||||
React.cloneElement(classicElement, props);
|
||||
|
||||
// ReactDOM.render
|
||||
const classicComponent: React.ClassicComponent<Props> = ReactDOM.render(classicElement, container);
|
||||
|
||||
//
|
||||
// React Components
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
const displayName: string | undefined = ClassicComponent.displayName;
|
||||
const defaultProps: Props = ClassicComponent.getDefaultProps ? ClassicComponent.getDefaultProps() : {} as Props;
|
||||
const propTypes: React.ValidationMap<Props> | undefined = ClassicComponent.propTypes;
|
||||
|
||||
//
|
||||
// Component API
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
// classic
|
||||
const isMounted: boolean = classicComponent.isMounted();
|
||||
classicComponent.replaceState({ inputValue: "???", seconds: 60 });
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
// Type definitions for create-react-class 15.6
|
||||
// Project: https://facebook.github.io/react/
|
||||
// Definitions by: John Gozde <https://github.com/jgoz>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
import { ComponentSpec, ClassicComponentClass } from "react";
|
||||
|
||||
declare namespace createReactClass {}
|
||||
declare function createReactClass<P, S>(spec: ComponentSpec<P, S>): ClassicComponentClass<P>;
|
||||
|
||||
export as namespace createReactClass;
|
||||
export = createReactClass;
|
||||
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"jsx": "preserve"
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"create-react-class-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user