Backport ts 2.6.1 fix to @types/react@15

For those of us who want to upgrade to the latest version of TypeScript, but haven't gotten around to upgrade our app to react 16 yet.

The bivarianceHack seems like an ugly workaround, but that's how @types/react@16 work atm.
This commit is contained in:
Avi Vahl
2017-11-03 20:12:28 +02:00
parent 99f93266bb
commit 2f8cf5bc0e

View File

@@ -78,7 +78,7 @@ declare namespace React {
type ComponentType<P = {}> = ComponentClass<P> | StatelessComponent<P>;
type Key = string | number;
type Ref<T> = string | ((instance: T | null) => any);
type Ref<T> = string | { bivarianceHack(instance: T | null): any }["bivarianceHack"];
// tslint:disable-next-line:interface-over-type-literal
type ComponentState = {};
@@ -521,7 +521,7 @@ declare namespace React {
// Event Handler Types
// ----------------------------------------------------------------------
type EventHandler<E extends SyntheticEvent<any>> = (event: E) => void;
type EventHandler<E extends SyntheticEvent<any>> = { bivarianceHack(event: E): void }["bivarianceHack"];
type ReactEventHandler<T> = EventHandler<SyntheticEvent<T>>;
@@ -3335,7 +3335,7 @@ declare namespace React {
// React.PropTypes
// ----------------------------------------------------------------------
type Validator<T> = (object: T, key: string, componentName: string, ...rest: any[]) => Error | null;
type Validator<T> = { bivarianceHack(object: T, key: string, componentName: string, ...rest: any[]): Error | null }["bivarianceHack"];
interface Requireable<T> extends Validator<T> {
isRequired: Validator<T>;