@types/react 16.9.24 → 16.9.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. react/README.md +1 -1
  2. react/index.d.ts +38 -2
  3. react/package.json +2 -2
react/README.md CHANGED
@@ -8,7 +8,7 @@ This package contains type definitions for React (http://facebook.github.io/reac
8
8
  Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react.
9
9
 
10
10
  ### Additional Details
11
- * Last updated: Thu, 27 Feb 2020 18:24:44 GMT
11
+ * Last updated: Fri, 20 Mar 2020 17:59:38 GMT
12
12
  * Dependencies: [@types/csstype](https://npmjs.com/package/@types/csstype), [@types/prop-types](https://npmjs.com/package/@types/prop-types)
13
13
  * Global values: `React`
14
14
 
react/index.d.ts CHANGED
@@ -82,17 +82,53 @@ declare namespace React {
82
82
  | ((props: P) => ReactElement | null)
83
83
  | (new (props: P) => Component<P, any>);
84
84
 
85
- type Key = string | number;
86
-
87
85
  interface RefObject<T> {
88
86
  readonly current: T | null;
89
87
  }
90
88
  type RefCallback<T> = { bivarianceHack(instance: T | null): void }["bivarianceHack"];
91
89
  type Ref<T> = RefCallback<T> | RefObject<T> | null;
92
90
  type LegacyRef<T> = string | Ref<T>;
91
+ /**
92
+ * Gets the instance type for a React element. The instance will be different for various component types:
93
+ *
94
+ * - React class components will be the class instance. So if you had `class Foo extends React.Component<{}> {}`
95
+ * and used `React.ElementRef<typeof Foo>` then the type would be the instance of `Foo`.
96
+ * - React stateless functional components do not have a backing instance and so `React.ElementRef<typeof Bar>`
97
+ * (when `Bar` is `function Bar() {}`) will give you the `undefined` type.
98
+ * - JSX intrinsics like `div` will give you their DOM instance. For `React.ElementRef<'div'>` that would be
99
+ * `HTMLDivElement`. For `React.ElementRef<'input'>` that would be `HTMLInputElement`.
100
+ * - React stateless functional components that forward a `ref` will give you the `ElementRef` of the forwarded
101
+ * to component.
102
+ *
103
+ * `C` must be the type _of_ a React component so you need to use typeof as in React.ElementRef<typeof MyComponent>.
104
+ *
105
+ * @todo In Flow, this works a little different with forwarded refs and the `AbstractComponent` that
106
+ * `React.forwardRef()` returns.
107
+ */
108
+ type ElementRef<
109
+ C extends
110
+ | ForwardRefExoticComponent<any>
111
+ | { new (props: any): Component<any> }
112
+ | ((props: any, context?: any) => ReactElement | null)
113
+ | keyof JSX.IntrinsicElements
114
+ > = C extends ForwardRefExoticComponent<infer FP>
115
+ ? FP extends RefAttributes<infer FC>
116
+ ? FC
117
+ : never
118
+ : C extends { new (props: any): Component<any> }
119
+ ? InstanceType<C>
120
+ : C extends ((props: any, context?: any) => ReactElement | null)
121
+ ? undefined
122
+ : C extends keyof JSX.IntrinsicElements
123
+ ? JSX.IntrinsicElements[C] extends DOMAttributes<infer E>
124
+ ? E
125
+ : never
126
+ : never;
93
127
 
94
128
  type ComponentState = any;
95
129
 
130
+ type Key = string | number;
131
+
96
132
  /**
97
133
  * @internal You shouldn't need to use this type since you never see these attributes
98
134
  * inside your component or have to validate them.
react/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/react",
3
- "version": "16.9.24",
3
+ "version": "16.9.25",
4
4
  "description": "TypeScript definitions for React",
5
5
  "license": "MIT",
6
6
  "contributors": [
@@ -129,6 +129,6 @@
129
129
  "@types/prop-types": "*",
130
130
  "csstype": "^2.2.0"
131
131
  },
132
- "typesPublisherContentHash": "17bd982329cdc89889c2c46e57a42af4f9372394f7b143680480005a2965bdf1",
132
+ "typesPublisherContentHash": "9734b6f2aa660752af997a294f88d260a7d58fdcb17c125c76f79f3d8f9d9555",
133
133
  "typeScriptVersion": "2.8"
134
134
  }