From 2f8cf5bc0e40b526be0c301a0d254ffb928ff7ad Mon Sep 17 00:00:00 2001 From: Avi Vahl Date: Fri, 3 Nov 2017 20:12:28 +0200 Subject: [PATCH] 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. --- types/react/v15/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/react/v15/index.d.ts b/types/react/v15/index.d.ts index c35e2df3c0..19cd290c7b 100644 --- a/types/react/v15/index.d.ts +++ b/types/react/v15/index.d.ts @@ -78,7 +78,7 @@ declare namespace React { type ComponentType

= ComponentClass

| StatelessComponent

; type Key = string | number; - type Ref = string | ((instance: T | null) => any); + type Ref = 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> = (event: E) => void; + type EventHandler> = { bivarianceHack(event: E): void }["bivarianceHack"]; type ReactEventHandler = EventHandler>; @@ -3335,7 +3335,7 @@ declare namespace React { // React.PropTypes // ---------------------------------------------------------------------- - type Validator = (object: T, key: string, componentName: string, ...rest: any[]) => Error | null; + type Validator = { bivarianceHack(object: T, key: string, componentName: string, ...rest: any[]): Error | null }["bivarianceHack"]; interface Requireable extends Validator { isRequired: Validator;