@types/react 18.2.54 → 18.2.56

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 CHANGED
@@ -8,7 +8,7 @@ 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: Mon, 05 Feb 2024 19:06:53 GMT
11
+ * Last updated: Sat, 17 Feb 2024 06:35:43 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
react/global.d.ts CHANGED
@@ -140,6 +140,7 @@ interface SVGPolygonElement extends SVGElement {}
140
140
  interface SVGPolylineElement extends SVGElement {}
141
141
  interface SVGRadialGradientElement extends SVGElement {}
142
142
  interface SVGRectElement extends SVGElement {}
143
+ interface SVGSetElement extends SVGElement {}
143
144
  interface SVGStopElement extends SVGElement {}
144
145
  interface SVGSwitchElement extends SVGElement {}
145
146
  interface SVGSymbolElement extends SVGElement {}
react/index.d.ts CHANGED
@@ -260,6 +260,21 @@ declare namespace React {
260
260
  ref?: LegacyRef<T> | undefined;
261
261
  }
262
262
 
263
+ /**
264
+ * Represents a JSX element.
265
+ *
266
+ * Where {@link ReactNode} represents everything that can be rendered, `ReactElement`
267
+ * only represents JSX.
268
+ *
269
+ * @template P The type of the props object
270
+ * @template T The type of the component or tag
271
+ *
272
+ * @example
273
+ *
274
+ * ```tsx
275
+ * const element: ReactElement = <div />;
276
+ * ```
277
+ */
263
278
  interface ReactElement<
264
279
  P = any,
265
280
  T extends string | JSXElementConstructor<any> = string | JSXElementConstructor<any>,
@@ -380,6 +395,8 @@ declare namespace React {
380
395
  /**
381
396
  * Represents all of the things React can render.
382
397
  *
398
+ * Where {@link ReactElement} only represents JSX, `ReactNode` represents everything that can be rendered.
399
+ *
383
400
  * @see {@link https://react-typescript-cheatsheet.netlify.app/docs/react-types/reactnode/ React TypeScript Cheatsheet}
384
401
  *
385
402
  * @example
@@ -551,6 +568,8 @@ declare namespace React {
551
568
  *
552
569
  * But they are, in fact, not callable - instead, they are objects which
553
570
  * are treated specially by the renderer.
571
+ *
572
+ * @template P The props the component accepts.
554
573
  */
555
574
  interface ExoticComponent<P = {}> {
556
575
  (props: P): ReactNode;
@@ -559,6 +578,8 @@ declare namespace React {
559
578
 
560
579
  /**
561
580
  * An {@link ExoticComponent} with a `displayName` property applied to it.
581
+ *
582
+ * @template P The props the component accepts.
562
583
  */
563
584
  interface NamedExoticComponent<P = {}> extends ExoticComponent<P> {
564
585
  /**
@@ -573,6 +594,8 @@ declare namespace React {
573
594
 
574
595
  /**
575
596
  * An {@link ExoticComponent} with a `propTypes` property applied to it.
597
+ *
598
+ * @template P The props the component accepts.
576
599
  */
577
600
  interface ProviderExoticComponent<P> extends ExoticComponent<P> {
578
601
  propTypes?: WeakValidationMap<P> | undefined;
@@ -581,6 +604,8 @@ declare namespace React {
581
604
  /**
582
605
  * Used to retrieve the type of a context object from a {@link Context}.
583
606
  *
607
+ * @template C The context object.
608
+ *
584
609
  * @example
585
610
  *
586
611
  * ```tsx
@@ -1620,6 +1645,24 @@ declare namespace React {
1620
1645
  readonly type: T;
1621
1646
  };
1622
1647
 
1648
+ /**
1649
+ * Lets you skip re-rendering a component when its props are unchanged.
1650
+ *
1651
+ * @see {@link https://react.dev/reference/react/memo React Docs}
1652
+ *
1653
+ * @param Component The component to memoize.
1654
+ * @param propsAreEqual A function that will be used to determine if the props have changed.
1655
+ *
1656
+ * @example
1657
+ *
1658
+ * ```tsx
1659
+ * import { memo } from 'react';
1660
+ *
1661
+ * const SomeComponent = memo(function SomeComponent(props: { foo: string }) {
1662
+ * // ...
1663
+ * });
1664
+ * ```
1665
+ */
1623
1666
  function memo<P extends object>(
1624
1667
  Component: FunctionComponent<P>,
1625
1668
  propsAreEqual?: (prevProps: Readonly<P>, nextProps: Readonly<P>) => boolean,
@@ -1629,26 +1672,70 @@ declare namespace React {
1629
1672
  propsAreEqual?: (prevProps: Readonly<ComponentProps<T>>, nextProps: Readonly<ComponentProps<T>>) => boolean,
1630
1673
  ): MemoExoticComponent<T>;
1631
1674
 
1632
- type LazyExoticComponent<T extends ComponentType<any>> = ExoticComponent<CustomComponentPropsWithRef<T>> & {
1675
+ interface LazyExoticComponent<T extends ComponentType<any>>
1676
+ extends ExoticComponent<CustomComponentPropsWithRef<T>>
1677
+ {
1633
1678
  readonly _result: T;
1634
- };
1679
+ }
1635
1680
 
1681
+ /**
1682
+ * Lets you defer loading a component’s code until it is rendered for the first time.
1683
+ *
1684
+ * @see {@link https://react.dev/reference/react/lazy React Docs}
1685
+ *
1686
+ * @param load A function that returns a `Promise` or another thenable (a `Promise`-like object with a
1687
+ * then method). React will not call `load` until the first time you attempt to render the returned
1688
+ * component. After React first calls load, it will wait for it to resolve, and then render the
1689
+ * resolved value’s `.default` as a React component. Both the returned `Promise` and the `Promise`’s
1690
+ * resolved value will be cached, so React will not call load more than once. If the `Promise` rejects,
1691
+ * React will throw the rejection reason for the nearest Error Boundary to handle.
1692
+ *
1693
+ * @example
1694
+ *
1695
+ * ```tsx
1696
+ * import { lazy } from 'react';
1697
+ *
1698
+ * const MarkdownPreview = lazy(() => import('./MarkdownPreview.js'));
1699
+ * ```
1700
+ */
1636
1701
  function lazy<T extends ComponentType<any>>(
1637
- factory: () => Promise<{ default: T }>,
1702
+ load: () => Promise<{ default: T }>,
1638
1703
  ): LazyExoticComponent<T>;
1639
1704
 
1640
1705
  //
1641
1706
  // React Hooks
1642
1707
  // ----------------------------------------------------------------------
1643
1708
 
1644
- // based on the code in https://github.com/facebook/react/pull/13968
1645
-
1646
- // Unlike the class component setState, the updates are not allowed to be partial
1709
+ /**
1710
+ * The instruction passed to a {@link Dispatch} function in {@link useState}
1711
+ * to tell React what the next value of the {@link useState} should be.
1712
+ *
1713
+ * Often found wrapped in {@link Dispatch}.
1714
+ *
1715
+ * @template S The type of the state.
1716
+ *
1717
+ * @example
1718
+ *
1719
+ * ```tsx
1720
+ * // This return type correctly represents the type of
1721
+ * // `setCount` in the example below.
1722
+ * const useCustomState = (): Dispatch<SetStateAction<number>> => {
1723
+ * const [count, setCount] = useState(0);
1724
+ *
1725
+ * return setCount;
1726
+ * }
1727
+ * ```
1728
+ */
1647
1729
  type SetStateAction<S> = S | ((prevState: S) => S);
1648
- // this technically does accept a second argument, but it's already under a deprecation warning
1649
- // and it's not even released so probably better to not define it.
1730
+
1731
+ /**
1732
+ * A function that can be used to update the state of a {@link useState}
1733
+ * or {@link useReducer} hook.
1734
+ */
1650
1735
  type Dispatch<A> = (value: A) => void;
1651
- // Since action _can_ be undefined, dispatch may be called without any parameters.
1736
+ /**
1737
+ * A {@link Dispatch} function can sometimes be called without any arguments.
1738
+ */
1652
1739
  type DispatchWithoutAction = () => void;
1653
1740
  // Unlike redux, the actions _can_ be anything
1654
1741
  type Reducer<S, A> = (prevState: S, action: A) => S;
@@ -4235,6 +4322,7 @@ declare global {
4235
4322
  polyline: React.SVGProps<SVGPolylineElement>;
4236
4323
  radialGradient: React.SVGProps<SVGRadialGradientElement>;
4237
4324
  rect: React.SVGProps<SVGRectElement>;
4325
+ set: React.SVGProps<SVGSetElement>;
4238
4326
  stop: React.SVGProps<SVGStopElement>;
4239
4327
  switch: React.SVGProps<SVGSwitchElement>;
4240
4328
  symbol: React.SVGProps<SVGSymbolElement>;
react/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/react",
3
- "version": "18.2.54",
3
+ "version": "18.2.56",
4
4
  "description": "TypeScript definitions for react",
5
5
  "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react",
6
6
  "license": "MIT",
@@ -201,6 +201,6 @@
201
201
  "@types/scheduler": "*",
202
202
  "csstype": "^3.0.2"
203
203
  },
204
- "typesPublisherContentHash": "922d20729fb53d28cfe96cc0465943dbba834f9fdb3686885737ee539e61333b",
204
+ "typesPublisherContentHash": "441f282a57e8185bea6f7d4ceb52897740d863fb37267b433337b6c790deeab4",
205
205
  "typeScriptVersion": "4.6"
206
206
  }
react/ts5.0/global.d.ts CHANGED
@@ -140,6 +140,7 @@ interface SVGPolygonElement extends SVGElement {}
140
140
  interface SVGPolylineElement extends SVGElement {}
141
141
  interface SVGRadialGradientElement extends SVGElement {}
142
142
  interface SVGRectElement extends SVGElement {}
143
+ interface SVGSetElement extends SVGElement {}
143
144
  interface SVGStopElement extends SVGElement {}
144
145
  interface SVGSwitchElement extends SVGElement {}
145
146
  interface SVGSymbolElement extends SVGElement {}
react/ts5.0/index.d.ts CHANGED
@@ -256,6 +256,21 @@ declare namespace React {
256
256
  ref?: LegacyRef<T> | undefined;
257
257
  }
258
258
 
259
+ /**
260
+ * Represents a JSX element.
261
+ *
262
+ * Where {@link ReactNode} represents everything that can be rendered, `ReactElement`
263
+ * only represents JSX.
264
+ *
265
+ * @template P The type of the props object
266
+ * @template T The type of the component or tag
267
+ *
268
+ * @example
269
+ *
270
+ * ```tsx
271
+ * const element: ReactElement = <div />;
272
+ * ```
273
+ */
259
274
  interface ReactElement<
260
275
  P = any,
261
276
  T extends string | JSXElementConstructor<any> = string | JSXElementConstructor<any>,
@@ -378,6 +393,8 @@ declare namespace React {
378
393
  /**
379
394
  * Represents all of the things React can render.
380
395
  *
396
+ * Where {@link ReactElement} only represents JSX, `ReactNode` represents everything that can be rendered.
397
+ *
381
398
  * @see {@link https://react-typescript-cheatsheet.netlify.app/docs/react-types/reactnode/ React TypeScript Cheatsheet}
382
399
  *
383
400
  * @example
@@ -549,6 +566,8 @@ declare namespace React {
549
566
  *
550
567
  * But they are, in fact, not callable - instead, they are objects which
551
568
  * are treated specially by the renderer.
569
+ *
570
+ * @template P The props the component accepts.
552
571
  */
553
572
  interface ExoticComponent<P = {}> {
554
573
  (props: P): ReactElement | null;
@@ -557,6 +576,8 @@ declare namespace React {
557
576
 
558
577
  /**
559
578
  * An {@link ExoticComponent} with a `displayName` property applied to it.
579
+ *
580
+ * @template P The props the component accepts.
560
581
  */
561
582
  interface NamedExoticComponent<P = {}> extends ExoticComponent<P> {
562
583
  /**
@@ -571,6 +592,8 @@ declare namespace React {
571
592
 
572
593
  /**
573
594
  * An {@link ExoticComponent} with a `propTypes` property applied to it.
595
+ *
596
+ * @template P The props the component accepts.
574
597
  */
575
598
  interface ProviderExoticComponent<P> extends ExoticComponent<P> {
576
599
  propTypes?: WeakValidationMap<P> | undefined;
@@ -579,6 +602,8 @@ declare namespace React {
579
602
  /**
580
603
  * Used to retrieve the type of a context object from a {@link Context}.
581
604
  *
605
+ * @template C The context object.
606
+ *
582
607
  * @example
583
608
  *
584
609
  * ```tsx
@@ -1618,6 +1643,24 @@ declare namespace React {
1618
1643
  readonly type: T;
1619
1644
  };
1620
1645
 
1646
+ /**
1647
+ * Lets you skip re-rendering a component when its props are unchanged.
1648
+ *
1649
+ * @see {@link https://react.dev/reference/react/memo React Docs}
1650
+ *
1651
+ * @param Component The component to memoize.
1652
+ * @param propsAreEqual A function that will be used to determine if the props have changed.
1653
+ *
1654
+ * @example
1655
+ *
1656
+ * ```tsx
1657
+ * import { memo } from 'react';
1658
+ *
1659
+ * const SomeComponent = memo(function SomeComponent(props: { foo: string }) {
1660
+ * // ...
1661
+ * });
1662
+ * ```
1663
+ */
1621
1664
  function memo<P extends object>(
1622
1665
  Component: FunctionComponent<P>,
1623
1666
  propsAreEqual?: (prevProps: Readonly<P>, nextProps: Readonly<P>) => boolean,
@@ -1631,8 +1674,28 @@ declare namespace React {
1631
1674
  readonly _result: T;
1632
1675
  };
1633
1676
 
1677
+ /**
1678
+ * Lets you defer loading a component’s code until it is rendered for the first time.
1679
+ *
1680
+ * @see {@link https://react.dev/reference/react/lazy React Docs}
1681
+ *
1682
+ * @param load A function that returns a `Promise` or another thenable (a `Promise`-like object with a
1683
+ * then method). React will not call `load` until the first time you attempt to render the returned
1684
+ * component. After React first calls load, it will wait for it to resolve, and then render the
1685
+ * resolved value’s `.default` as a React component. Both the returned `Promise` and the `Promise`’s
1686
+ * resolved value will be cached, so React will not call load more than once. If the `Promise` rejects,
1687
+ * React will throw the rejection reason for the nearest Error Boundary to handle.
1688
+ *
1689
+ * @example
1690
+ *
1691
+ * ```tsx
1692
+ * import { lazy } from 'react';
1693
+ *
1694
+ * const MarkdownPreview = lazy(() => import('./MarkdownPreview.js'));
1695
+ * ```
1696
+ */
1634
1697
  function lazy<T extends ComponentType<any>>(
1635
- factory: () => Promise<{ default: T }>,
1698
+ load: () => Promise<{ default: T }>,
1636
1699
  ): LazyExoticComponent<T>;
1637
1700
 
1638
1701
  //
@@ -1641,12 +1704,36 @@ declare namespace React {
1641
1704
 
1642
1705
  // based on the code in https://github.com/facebook/react/pull/13968
1643
1706
 
1644
- // Unlike the class component setState, the updates are not allowed to be partial
1707
+ /**
1708
+ * The instruction passed to a {@link Dispatch} function in {@link useState}
1709
+ * to tell React what the next value of the {@link useState} should be.
1710
+ *
1711
+ * Often found wrapped in {@link Dispatch}.
1712
+ *
1713
+ * @template S The type of the state.
1714
+ *
1715
+ * @example
1716
+ *
1717
+ * ```tsx
1718
+ * // This return type correctly represents the type of
1719
+ * // `setCount` in the example below.
1720
+ * const useCustomState = (): Dispatch<SetStateAction<number>> => {
1721
+ * const [count, setCount] = useState(0);
1722
+ *
1723
+ * return setCount;
1724
+ * }
1725
+ * ```
1726
+ */
1645
1727
  type SetStateAction<S> = S | ((prevState: S) => S);
1646
- // this technically does accept a second argument, but it's already under a deprecation warning
1647
- // and it's not even released so probably better to not define it.
1728
+
1729
+ /**
1730
+ * A function that can be used to update the state of a {@link useState}
1731
+ * or {@link useReducer} hook.
1732
+ */
1648
1733
  type Dispatch<A> = (value: A) => void;
1649
- // Since action _can_ be undefined, dispatch may be called without any parameters.
1734
+ /**
1735
+ * A {@link Dispatch} function can sometimes be called without any arguments.
1736
+ */
1650
1737
  type DispatchWithoutAction = () => void;
1651
1738
  // Unlike redux, the actions _can_ be anything
1652
1739
  type Reducer<S, A> = (prevState: S, action: A) => S;
@@ -4218,6 +4305,7 @@ declare global {
4218
4305
  polyline: React.SVGProps<SVGPolylineElement>;
4219
4306
  radialGradient: React.SVGProps<SVGRadialGradientElement>;
4220
4307
  rect: React.SVGProps<SVGRectElement>;
4308
+ set: React.SVGProps<SVGSetElement>;
4221
4309
  stop: React.SVGProps<SVGStopElement>;
4222
4310
  switch: React.SVGProps<SVGSwitchElement>;
4223
4311
  symbol: React.SVGProps<SVGSymbolElement>;