@types/react 18.2.60 → 18.2.61
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.
- react/README.md +2 -2
- react/index.d.ts +53 -12
- react/package.json +7 -2
- react/ts5.0/index.d.ts +51 -12
react/README.md
CHANGED
@@ -8,8 +8,8 @@ This package contains type definitions for react (https://react.dev/).
|
|
8
8
|
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react.
|
9
9
|
|
10
10
|
### Additional Details
|
11
|
-
* Last updated:
|
11
|
+
* Last updated: Thu, 29 Feb 2024 12:09:49 GMT
|
12
12
|
* Dependencies: [@types/prop-types](https://npmjs.com/package/@types/prop-types), [@types/scheduler](https://npmjs.com/package/@types/scheduler), [csstype](https://npmjs.com/package/csstype)
|
13
13
|
|
14
14
|
# Credits
|
15
|
-
These definitions were written by [Asana](https://asana.com), [AssureSign](http://www.assuresign.com), [Microsoft](https://microsoft.com), [John Reilly](https://github.com/johnnyreilly), [Benoit Benezech](https://github.com/bbenezech), [Patricio Zavolinsky](https://github.com/pzavolinsky), [Eric Anderson](https://github.com/ericanderson), [Dovydas Navickas](https://github.com/DovydasNavickas), [Josh Rutherford](https://github.com/theruther4d), [Guilherme Hübner](https://github.com/guilhermehubner), [Ferdy Budhidharma](https://github.com/ferdaber), [Johann Rakotoharisoa](https://github.com/jrakotoharisoa), [Olivier Pascal](https://github.com/pascaloliv), [Martin Hochel](https://github.com/hotell), [Frank Li](https://github.com/franklixuefei), [Jessica Franco](https://github.com/Jessidhia), [Saransh Kataria](https://github.com/saranshkataria), [Kanitkorn Sujautra](https://github.com/lukyth), [Sebastian Silbermann](https://github.com/eps1lon), [Kyle Scully](https://github.com/zieka), [Cong Zhang](https://github.com/dancerphil), [Dimitri Mitropoulos](https://github.com/dimitropoulos), [JongChan Choi](https://github.com/disjukr), [Victor Magalhães](https://github.com/vhfmag), [Dale Tan](https://github.com/hellatan), [Priyanshu Rav](https://github.com/priyanshurav),
|
15
|
+
These definitions were written by [Asana](https://asana.com), [AssureSign](http://www.assuresign.com), [Microsoft](https://microsoft.com), [John Reilly](https://github.com/johnnyreilly), [Benoit Benezech](https://github.com/bbenezech), [Patricio Zavolinsky](https://github.com/pzavolinsky), [Eric Anderson](https://github.com/ericanderson), [Dovydas Navickas](https://github.com/DovydasNavickas), [Josh Rutherford](https://github.com/theruther4d), [Guilherme Hübner](https://github.com/guilhermehubner), [Ferdy Budhidharma](https://github.com/ferdaber), [Johann Rakotoharisoa](https://github.com/jrakotoharisoa), [Olivier Pascal](https://github.com/pascaloliv), [Martin Hochel](https://github.com/hotell), [Frank Li](https://github.com/franklixuefei), [Jessica Franco](https://github.com/Jessidhia), [Saransh Kataria](https://github.com/saranshkataria), [Kanitkorn Sujautra](https://github.com/lukyth), [Sebastian Silbermann](https://github.com/eps1lon), [Kyle Scully](https://github.com/zieka), [Cong Zhang](https://github.com/dancerphil), [Dimitri Mitropoulos](https://github.com/dimitropoulos), [JongChan Choi](https://github.com/disjukr), [Victor Magalhães](https://github.com/vhfmag), [Dale Tan](https://github.com/hellatan), [Priyanshu Rav](https://github.com/priyanshurav), [Dmitry Semigradsky](https://github.com/Semigradsky), and [Matt Pocock](https://github.com/mattpocock).
|
react/index.d.ts
CHANGED
@@ -189,6 +189,7 @@ declare namespace React {
|
|
189
189
|
* <div ref="myRef" />
|
190
190
|
* ```
|
191
191
|
*/
|
192
|
+
// TODO: Remove the string ref special case from `PropsWithRef` once we remove LegacyRef
|
192
193
|
type LegacyRef<T> = string | Ref<T>;
|
193
194
|
|
194
195
|
/**
|
@@ -217,9 +218,10 @@ declare namespace React {
|
|
217
218
|
> =
|
218
219
|
// need to check first if `ref` is a valid prop for ts@3.0
|
219
220
|
// otherwise it will infer `{}` instead of `never`
|
220
|
-
"ref" extends keyof ComponentPropsWithRef<C>
|
221
|
+
"ref" extends keyof ComponentPropsWithRef<C>
|
222
|
+
? NonNullable<ComponentPropsWithRef<C>["ref"]> extends RefAttributes<
|
221
223
|
infer Instance
|
222
|
-
> ? Instance
|
224
|
+
>["ref"] ? Instance
|
223
225
|
: never
|
224
226
|
: never;
|
225
227
|
|
@@ -232,9 +234,55 @@ declare namespace React {
|
|
232
234
|
*/
|
233
235
|
type Key = string | number | bigint;
|
234
236
|
|
237
|
+
/**
|
238
|
+
* @internal The props any component can receive.
|
239
|
+
* You don't have to add this type. All components automatically accept these props.
|
240
|
+
* ```tsx
|
241
|
+
* const Component = () => <div />;
|
242
|
+
* <Component key="one" />
|
243
|
+
* ```
|
244
|
+
*
|
245
|
+
* WARNING: The implementation of a component will never have access to these attributes.
|
246
|
+
* The following example would be incorrect usage because {@link Component} would never have access to `key`:
|
247
|
+
* ```tsx
|
248
|
+
* const Component = (props: React.Attributes) => props.key;
|
249
|
+
* ```
|
250
|
+
*/
|
235
251
|
interface Attributes {
|
236
252
|
key?: Key | null | undefined;
|
237
253
|
}
|
254
|
+
/**
|
255
|
+
* The props any component accepting refs can receive.
|
256
|
+
* Class components, built-in browser components (e.g. `div`) and forwardRef components can receive refs and automatically accept these props.
|
257
|
+
* ```tsx
|
258
|
+
* const Component = forwardRef(() => <div />);
|
259
|
+
* <Component ref={(current) => console.log(current)} />
|
260
|
+
* ```
|
261
|
+
*
|
262
|
+
* You only need this type if you manually author the types of props that need to be compatible with legacy refs.
|
263
|
+
* ```tsx
|
264
|
+
* interface Props extends React.RefAttributes<HTMLDivElement> {}
|
265
|
+
* declare const Component: React.FunctionComponent<Props>;
|
266
|
+
* ```
|
267
|
+
*
|
268
|
+
* Otherwise it's simpler to directly use {@link Ref} since you can safely use the
|
269
|
+
* props type to describe to props that a consumer can pass to the component
|
270
|
+
* as well as describing the props the implementation of a component "sees".
|
271
|
+
* {@link RefAttributes} is generally not safe to describe both consumer and seen props.
|
272
|
+
*
|
273
|
+
* ```tsx
|
274
|
+
* interface Props extends {
|
275
|
+
* ref?: React.Ref<HTMLDivElement> | undefined;
|
276
|
+
* }
|
277
|
+
* declare const Component: React.FunctionComponent<Props>;
|
278
|
+
* ```
|
279
|
+
*
|
280
|
+
* WARNING: The implementation of a component will not have access to the same type in versions of React supporting string refs.
|
281
|
+
* The following example would be incorrect usage because {@link Component} would never have access to a `ref` with type `string`
|
282
|
+
* ```tsx
|
283
|
+
* const Component = (props: React.RefAttributes) => props.ref;
|
284
|
+
* ```
|
285
|
+
*/
|
238
286
|
interface RefAttributes<T> extends Attributes {
|
239
287
|
/**
|
240
288
|
* Allows getting a ref to the component instance.
|
@@ -243,21 +291,13 @@ declare namespace React {
|
|
243
291
|
*
|
244
292
|
* @see {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs}
|
245
293
|
*/
|
246
|
-
ref?:
|
294
|
+
ref?: LegacyRef<T> | undefined;
|
247
295
|
}
|
248
296
|
|
249
297
|
/**
|
250
298
|
* Represents the built-in attributes available to class components.
|
251
299
|
*/
|
252
|
-
interface ClassAttributes<T> extends
|
253
|
-
/**
|
254
|
-
* Allows getting a ref to the component instance.
|
255
|
-
* Once the component unmounts, React will set `ref.current` to `null`
|
256
|
-
* (or call the ref with `null` if you passed a callback ref).
|
257
|
-
*
|
258
|
-
* @see {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom React Docs}
|
259
|
-
*/
|
260
|
-
ref?: LegacyRef<T> | undefined;
|
300
|
+
interface ClassAttributes<T> extends RefAttributes<T> {
|
261
301
|
}
|
262
302
|
|
263
303
|
/**
|
@@ -1522,6 +1562,7 @@ declare namespace React {
|
|
1522
1562
|
P extends any ? ("ref" extends keyof P ? Omit<P, "ref"> : P) : P;
|
1523
1563
|
/** Ensures that the props do not include string ref, which cannot be forwarded */
|
1524
1564
|
type PropsWithRef<P> =
|
1565
|
+
// Note: String refs can be forwarded. We can't fix this bug without breaking a bunch of libraries now though.
|
1525
1566
|
// Just "P extends { ref?: infer R }" looks sufficient, but R will infer as {} if P is {}.
|
1526
1567
|
"ref" extends keyof P
|
1527
1568
|
? P extends { ref?: infer R | undefined }
|
react/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@types/react",
|
3
|
-
"version": "18.2.
|
3
|
+
"version": "18.2.61",
|
4
4
|
"description": "TypeScript definitions for react",
|
5
5
|
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react",
|
6
6
|
"license": "MIT",
|
@@ -136,6 +136,11 @@
|
|
136
136
|
"name": "Dmitry Semigradsky",
|
137
137
|
"githubUsername": "Semigradsky",
|
138
138
|
"url": "https://github.com/Semigradsky"
|
139
|
+
},
|
140
|
+
{
|
141
|
+
"name": "Matt Pocock",
|
142
|
+
"githubUsername": "mattpocock",
|
143
|
+
"url": "https://github.com/mattpocock"
|
139
144
|
}
|
140
145
|
],
|
141
146
|
"main": "",
|
@@ -201,6 +206,6 @@
|
|
201
206
|
"@types/scheduler": "*",
|
202
207
|
"csstype": "^3.0.2"
|
203
208
|
},
|
204
|
-
"typesPublisherContentHash": "
|
209
|
+
"typesPublisherContentHash": "c969d4c49fc5be8c9712e6a7cc38c14d908da611af884cf2da96ba279fe8495e",
|
205
210
|
"typeScriptVersion": "4.6"
|
206
211
|
}
|
react/ts5.0/index.d.ts
CHANGED
@@ -186,6 +186,7 @@ declare namespace React {
|
|
186
186
|
* <div ref="myRef" />
|
187
187
|
* ```
|
188
188
|
*/
|
189
|
+
// TODO: Remove the string ref special case from `PropsWithRef` once we remove LegacyRef
|
189
190
|
type LegacyRef<T> = string | Ref<T>;
|
190
191
|
|
191
192
|
/**
|
@@ -214,9 +215,10 @@ declare namespace React {
|
|
214
215
|
> =
|
215
216
|
// need to check first if `ref` is a valid prop for ts@3.0
|
216
217
|
// otherwise it will infer `{}` instead of `never`
|
217
|
-
"ref" extends keyof ComponentPropsWithRef<C>
|
218
|
+
"ref" extends keyof ComponentPropsWithRef<C>
|
219
|
+
? NonNullable<ComponentPropsWithRef<C>["ref"]> extends RefAttributes<
|
218
220
|
infer Instance
|
219
|
-
> ? Instance
|
221
|
+
>["ref"] ? Instance
|
220
222
|
: never
|
221
223
|
: never;
|
222
224
|
|
@@ -230,30 +232,66 @@ declare namespace React {
|
|
230
232
|
type Key = string | number | bigint;
|
231
233
|
|
232
234
|
/**
|
233
|
-
* @internal
|
234
|
-
*
|
235
|
+
* @internal The props any component can receive.
|
236
|
+
* You don't have to add this type. All components automatically accept these props.
|
237
|
+
* ```tsx
|
238
|
+
* const Component = () => <div />;
|
239
|
+
* <Component key="one" />
|
240
|
+
* ```
|
241
|
+
*
|
242
|
+
* WARNING: The implementation of a component will never have access to these attributes.
|
243
|
+
* The following example would be incorrect usage because {@link Component} would never have access to `key`:
|
244
|
+
* ```tsx
|
245
|
+
* const Component = (props: React.Attributes) => props.key;
|
246
|
+
* ```
|
235
247
|
*/
|
236
248
|
interface Attributes {
|
237
249
|
key?: Key | null | undefined;
|
238
250
|
}
|
251
|
+
/**
|
252
|
+
* The props any component accepting refs can receive.
|
253
|
+
* Class components, built-in browser components (e.g. `div`) and forwardRef components can receive refs and automatically accept these props.
|
254
|
+
* ```tsx
|
255
|
+
* const Component = forwardRef(() => <div />);
|
256
|
+
* <Component ref={(current) => console.log(current)} />
|
257
|
+
* ```
|
258
|
+
*
|
259
|
+
* You only need this type if you manually author the types of props that need to be compatible with legacy refs.
|
260
|
+
* ```tsx
|
261
|
+
* interface Props extends React.RefAttributes<HTMLDivElement> {}
|
262
|
+
* declare const Component: React.FunctionComponent<Props>;
|
263
|
+
* ```
|
264
|
+
*
|
265
|
+
* Otherwise it's simpler to directly use {@link Ref} since you can safely use the
|
266
|
+
* props type to describe to props that a consumer can pass to the component
|
267
|
+
* as well as describing the props the implementation of a component "sees".
|
268
|
+
* {@link RefAttributes} is generally not safe to describe both consumer and seen props.
|
269
|
+
*
|
270
|
+
* ```tsx
|
271
|
+
* interface Props extends {
|
272
|
+
* ref?: React.Ref<HTMLDivElement> | undefined;
|
273
|
+
* }
|
274
|
+
* declare const Component: React.FunctionComponent<Props>;
|
275
|
+
* ```
|
276
|
+
*
|
277
|
+
* WARNING: The implementation of a component will not have access to the same type in versions of React supporting string refs.
|
278
|
+
* The following example would be incorrect usage because {@link Component} would never have access to a `ref` with type `string`
|
279
|
+
* ```tsx
|
280
|
+
* const Component = (props: React.RefAttributes) => props.ref;
|
281
|
+
* ```
|
282
|
+
*/
|
239
283
|
interface RefAttributes<T> extends Attributes {
|
240
284
|
/**
|
241
285
|
* Allows getting a ref to the component instance.
|
242
286
|
* Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref).
|
243
287
|
* @see {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom}
|
244
288
|
*/
|
245
|
-
ref?:
|
289
|
+
ref?: LegacyRef<T> | undefined;
|
246
290
|
}
|
247
291
|
/**
|
248
292
|
* Represents the built-in attributes available to class components.
|
249
293
|
*/
|
250
|
-
interface ClassAttributes<T> extends
|
251
|
-
/**
|
252
|
-
* Allows getting a ref to the component instance.
|
253
|
-
* Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref).
|
254
|
-
* @see {@link https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom}
|
255
|
-
*/
|
256
|
-
ref?: LegacyRef<T> | undefined;
|
294
|
+
interface ClassAttributes<T> extends RefAttributes<T> {
|
257
295
|
}
|
258
296
|
|
259
297
|
/**
|
@@ -1520,6 +1558,7 @@ declare namespace React {
|
|
1520
1558
|
P extends any ? ("ref" extends keyof P ? Omit<P, "ref"> : P) : P;
|
1521
1559
|
/** Ensures that the props do not include string ref, which cannot be forwarded */
|
1522
1560
|
type PropsWithRef<P> =
|
1561
|
+
// Note: String refs can be forwarded. We can't fix this bug without breaking a bunch of libraries now though.
|
1523
1562
|
// Just "P extends { ref?: infer R }" looks sufficient, but R will infer as {} if P is {}.
|
1524
1563
|
"ref" extends keyof P
|
1525
1564
|
? P extends { ref?: infer R | undefined }
|