@types/react 17.0.43 → 18.0.1

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 (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, 24 Mar 2022 22:01:43 GMT
11
+ * Last updated: Sat, 09 Apr 2022 18:01:20 GMT
12
12
  * Dependencies: [@types/csstype](https://npmjs.com/package/@types/csstype), [@types/prop-types](https://npmjs.com/package/@types/prop-types), [@types/scheduler](https://npmjs.com/package/@types/scheduler)
13
13
  * Global values: `React`
14
14
 
react/experimental.d.ts CHANGED
@@ -39,6 +39,15 @@ import React = require('./next');
39
39
  export {};
40
40
 
41
41
  declare module '.' {
42
+ export interface SuspenseProps {
43
+ /**
44
+ * The presence of this prop indicates that the content is computationally expensive to render.
45
+ * In other words, the tree is CPU bound and not I/O bound (e.g. due to fetching data).
46
+ * @see {@link https://github.com/facebook/react/pull/19936}
47
+ */
48
+ unstable_expectedLoadTime?: number | undefined;
49
+ }
50
+
42
51
  export type SuspenseListRevealOrder = 'forwards' | 'backwards' | 'together';
43
52
  export type SuspenseListTailMode = 'collapsed' | 'hidden';
44
53
 
react/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Type definitions for React 17.0
1
+ // Type definitions for React 18.0
2
2
  // Project: http://facebook.github.io/react/
3
3
  // Definitions by: Asana <https://asana.com>
4
4
  // AssureSign <http://www.assuresign.com>
@@ -29,10 +29,6 @@
29
29
  // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
30
30
  // TypeScript Version: 2.8
31
31
 
32
- // NOTE: Users of the upcoming React 18 release should add a reference
33
- // to 'react/next' in their project. See next.d.ts's top comment
34
- // for reference and documentation on how exactly to do it.
35
-
36
32
  // NOTE: Users of the `experimental` builds of React should add a reference
37
33
  // to 'react/experimental' in their project. See experimental.d.ts's top comment
38
34
  // for reference and documentation on how exactly to do it.
@@ -60,6 +56,7 @@ type Booleanish = boolean | 'true' | 'false';
60
56
  declare const UNDEFINED_VOID_ONLY: unique symbol;
61
57
  // Destructors are only allowed to return void.
62
58
  type Destructor = () => void | { [UNDEFINED_VOID_ONLY]: never };
59
+ type VoidOrUndefinedOnly = void | { [UNDEFINED_VOID_ONLY]: never };
63
60
 
64
61
  // tslint:disable-next-line:export-just-namespace
65
62
  export = React;
@@ -75,10 +72,6 @@ declare namespace React {
75
72
  [K in keyof JSX.IntrinsicElements]: P extends JSX.IntrinsicElements[K] ? K : never
76
73
  }[keyof JSX.IntrinsicElements] |
77
74
  ComponentType<P>;
78
- /**
79
- * @deprecated Please use `ElementType`
80
- */
81
- type ReactType<P = any> = ElementType<P>;
82
75
  type ComponentType<P = {}> = ComponentClass<P> | FunctionComponent<P>;
83
76
 
84
77
  type JSXElementConstructor<P> =
@@ -155,11 +148,6 @@ declare namespace React {
155
148
  P = Pick<ComponentProps<T>, Exclude<keyof ComponentProps<T>, 'key' | 'ref'>>
156
149
  > extends ReactElement<P, Exclude<T, number>> { }
157
150
 
158
- /**
159
- * @deprecated Please use `FunctionComponentElement`
160
- */
161
- type SFCElement<P> = FunctionComponentElement<P>;
162
-
163
151
  interface FunctionComponentElement<P> extends ReactElement<P, FunctionComponent<P>> {
164
152
  ref?: ('ref' extends keyof P ? P extends { ref?: infer R | undefined } ? R : never : never) | undefined;
165
153
  }
@@ -237,7 +225,7 @@ declare namespace React {
237
225
  * @deprecated Use either `ReactNode[]` if you need an array or `Iterable<ReactNode>` if its passed to a host component.
238
226
  */
239
227
  interface ReactNodeArray extends ReadonlyArray<ReactNode> {}
240
- type ReactFragment = {} | Iterable<ReactNode>;
228
+ type ReactFragment = Iterable<ReactNode>;
241
229
  type ReactNode = ReactChild | ReactFragment | ReactPortal | boolean | null | undefined;
242
230
 
243
231
  //
@@ -396,16 +384,10 @@ declare namespace React {
396
384
  interface SuspenseProps {
397
385
  children?: ReactNode | undefined;
398
386
 
399
- // TODO(react18): `fallback?: ReactNode;`
400
387
  /** A fallback react tree to show when a Suspense child (like React.lazy) suspends */
401
- fallback: NonNullable<ReactNode>|null;
388
+ fallback?: ReactNode;
402
389
  }
403
390
 
404
- // TODO(react18): Updated JSDoc to reflect that Suspense works on the server.
405
- /**
406
- * This feature is not yet available for server-side rendering.
407
- * Suspense support will be added in a later release.
408
- */
409
391
  const Suspense: ExoticComponent<SuspenseProps>;
410
392
  const version: string;
411
393
 
@@ -476,8 +458,7 @@ declare namespace React {
476
458
  *
477
459
  * @see https://reactjs.org/docs/context.html
478
460
  */
479
- // TODO (TypeScript 3.0): unknown
480
- context: any;
461
+ context: unknown;
481
462
 
482
463
  constructor(props: Readonly<P> | P);
483
464
  /**
@@ -497,12 +478,7 @@ declare namespace React {
497
478
  forceUpdate(callback?: () => void): void;
498
479
  render(): ReactNode;
499
480
 
500
- // React.Props<T> is now deprecated, which means that the `children`
501
- // property is not available on `P` by default, even though you can
502
- // always pass children as variadic arguments to `createElement`.
503
- // In the future, if we can define its call signature conditionally
504
- // on the existence of `children` in `P`, then we should remove this.
505
- readonly props: Readonly<P> & Readonly<{ children?: ReactNode | undefined }>;
481
+ readonly props: Readonly<P>;
506
482
  state: Readonly<S>;
507
483
  /**
508
484
  * @deprecated
@@ -529,26 +505,10 @@ declare namespace React {
529
505
  // Class Interfaces
530
506
  // ----------------------------------------------------------------------
531
507
 
532
- /**
533
- * @deprecated as of recent React versions, function components can no
534
- * longer be considered 'stateless'. Please use `FunctionComponent` instead.
535
- *
536
- * @see [React Hooks](https://reactjs.org/docs/hooks-intro.html)
537
- */
538
- type SFC<P = {}> = FunctionComponent<P>;
539
-
540
- /**
541
- * @deprecated as of recent React versions, function components can no
542
- * longer be considered 'stateless'. Please use `FunctionComponent` instead.
543
- *
544
- * @see [React Hooks](https://reactjs.org/docs/hooks-intro.html)
545
- */
546
- type StatelessComponent<P = {}> = FunctionComponent<P>;
547
-
548
508
  type FC<P = {}> = FunctionComponent<P>;
549
509
 
550
510
  interface FunctionComponent<P = {}> {
551
- (props: PropsWithChildren<P>, context?: any): ReactElement<any, any> | null;
511
+ (props: P, context?: any): ReactElement<any, any> | null;
552
512
  propTypes?: WeakValidationMap<P> | undefined;
553
513
  contextTypes?: ValidationMap<any> | undefined;
554
514
  defaultProps?: Partial<P> | undefined;
@@ -568,7 +528,7 @@ declare namespace React {
568
528
  type ForwardedRef<T> = ((instance: T | null) => void) | MutableRefObject<T | null> | null;
569
529
 
570
530
  interface ForwardRefRenderFunction<T, P = {}> {
571
- (props: PropsWithChildren<P>, ref: ForwardedRef<T>): ReactElement | null;
531
+ (props: P, ref: ForwardedRef<T>): ReactElement | null;
572
532
  displayName?: string | undefined;
573
533
  // explicit rejected with `never` required due to
574
534
  // https://github.com/microsoft/TypeScript/issues/36826
@@ -582,12 +542,6 @@ declare namespace React {
582
542
  propTypes?: never | undefined;
583
543
  }
584
544
 
585
- /**
586
- * @deprecated Use ForwardRefRenderFunction. forwardRef doesn't accept a
587
- * "real" component.
588
- */
589
- interface RefForwardingComponent <T, P = {}> extends ForwardRefRenderFunction<T, P> {}
590
-
591
545
  interface ComponentClass<P = {}, S = ComponentState> extends StaticLifecycle<P, S> {
592
546
  new (props: P, context?: any): Component<P, S>;
593
547
  propTypes?: WeakValidationMap<P> | undefined;
@@ -862,7 +816,7 @@ declare namespace React {
862
816
 
863
817
  function memo<P extends object>(
864
818
  Component: FunctionComponent<P>,
865
- propsAreEqual?: (prevProps: Readonly<PropsWithChildren<P>>, nextProps: Readonly<PropsWithChildren<P>>) => boolean
819
+ propsAreEqual?: (prevProps: Readonly<P>, nextProps: Readonly<P>) => boolean
866
820
  ): NamedExoticComponent<P>;
867
821
  function memo<T extends ComponentType<any>>(
868
822
  Component: T,
@@ -901,8 +855,7 @@ declare namespace React {
901
855
  // The identity check is done with the SameValue algorithm (Object.is), which is stricter than ===
902
856
  type ReducerStateWithoutAction<R extends ReducerWithoutAction<any>> =
903
857
  R extends ReducerWithoutAction<infer S> ? S : never;
904
- // TODO (TypeScript 3.0): ReadonlyArray<unknown>
905
- type DependencyList = ReadonlyArray<any>;
858
+ type DependencyList = ReadonlyArray<unknown>;
906
859
 
907
860
  // NOTE: callbacks are _only_ allowed to return either void, or a destructor.
908
861
  type EffectCallback = () => (void | Destructor);
@@ -1109,8 +1062,10 @@ declare namespace React {
1109
1062
  * @version 16.8.0
1110
1063
  * @see https://reactjs.org/docs/hooks-reference.html#usecallback
1111
1064
  */
1112
- // TODO (TypeScript 3.0): <T extends (...args: never[]) => unknown>
1113
- function useCallback<T extends (...args: any[]) => any>(callback: T, deps: DependencyList): T;
1065
+ // A specific function type would not trigger implicit any.
1066
+ // See https://github.com/DefinitelyTyped/DefinitelyTyped/issues/52873#issuecomment-845806435 for a comparison between `Function` and more specific types.
1067
+ // tslint:disable-next-line ban-types
1068
+ function useCallback<T extends Function>(callback: T, deps: DependencyList): T;
1114
1069
  /**
1115
1070
  * `useMemo` will only recompute the memoized value when one of the `deps` has changed.
1116
1071
  *
@@ -1132,6 +1087,83 @@ declare namespace React {
1132
1087
  // it's just the function name without the "use" prefix.
1133
1088
  function useDebugValue<T>(value: T, format?: (value: T) => any): void;
1134
1089
 
1090
+ // must be synchronous
1091
+ export type TransitionFunction = () => VoidOrUndefinedOnly;
1092
+ // strange definition to allow vscode to show documentation on the invocation
1093
+ export interface TransitionStartFunction {
1094
+ /**
1095
+ * State updates caused inside the callback are allowed to be deferred.
1096
+ *
1097
+ * **If some state update causes a component to suspend, that state update should be wrapped in a transition.**
1098
+ *
1099
+ * @param callback A _synchronous_ function which causes state updates that can be deferred.
1100
+ */
1101
+ (callback: TransitionFunction): void;
1102
+ }
1103
+
1104
+ /**
1105
+ * Returns a deferred version of the value that may “lag behind” it for at most `timeoutMs`.
1106
+ *
1107
+ * This is commonly used to keep the interface responsive when you have something that renders immediately
1108
+ * based on user input and something that needs to wait for a data fetch.
1109
+ *
1110
+ * A good example of this is a text input.
1111
+ *
1112
+ * @param value The value that is going to be deferred
1113
+ *
1114
+ * @see https://reactjs.org/docs/concurrent-mode-reference.html#usedeferredvalue
1115
+ */
1116
+ export function useDeferredValue<T>(value: T): T;
1117
+
1118
+ /**
1119
+ * Allows components to avoid undesirable loading states by waiting for content to load
1120
+ * before transitioning to the next screen. It also allows components to defer slower,
1121
+ * data fetching updates until subsequent renders so that more crucial updates can be
1122
+ * rendered immediately.
1123
+ *
1124
+ * The `useTransition` hook returns two values in an array.
1125
+ *
1126
+ * The first is a boolean, React’s way of informing us whether we’re waiting for the transition to finish.
1127
+ * The second is a function that takes a callback. We can use it to tell React which state we want to defer.
1128
+ *
1129
+ * **If some state update causes a component to suspend, that state update should be wrapped in a transition.**
1130
+ *
1131
+ * @param config An optional object with `timeoutMs`
1132
+ *
1133
+ * @see https://reactjs.org/docs/concurrent-mode-reference.html#usetransition
1134
+ */
1135
+ export function useTransition(): [boolean, TransitionStartFunction];
1136
+
1137
+ /**
1138
+ * Similar to `useTransition` but allows uses where hooks are not available.
1139
+ *
1140
+ * @param callback A _synchronous_ function which causes state updates that can be deferred.
1141
+ */
1142
+ export function startTransition(scope: TransitionFunction): void;
1143
+
1144
+ export function useId(): string;
1145
+
1146
+ /**
1147
+ * @param effect Imperative function that can return a cleanup function
1148
+ * @param deps If present, effect will only activate if the values in the list change.
1149
+ *
1150
+ * @see https://github.com/facebook/react/pull/21913
1151
+ */
1152
+ export function useInsertionEffect(effect: EffectCallback, deps?: DependencyList): void;
1153
+
1154
+ /**
1155
+ * @param subscribe
1156
+ * @param getSnapshot
1157
+ *
1158
+ * @see https://github.com/reactwg/react-18/discussions/86
1159
+ */
1160
+ // keep in sync with `useSyncExternalStore` from `use-sync-external-store`
1161
+ export function useSyncExternalStore<Snapshot>(
1162
+ subscribe: (onStoreChange: () => void) => () => void,
1163
+ getSnapshot: () => Snapshot,
1164
+ getServerSnapshot?: () => Snapshot,
1165
+ ): Snapshot;
1166
+
1135
1167
  //
1136
1168
  // Event System
1137
1169
  // ----------------------------------------------------------------------
@@ -1316,26 +1348,6 @@ declare namespace React {
1316
1348
  // Props / DOM Attributes
1317
1349
  // ----------------------------------------------------------------------
1318
1350
 
1319
- /**
1320
- * @deprecated. This was used to allow clients to pass `ref` and `key`
1321
- * to `createElement`, which is no longer necessary due to intersection
1322
- * types. If you need to declare a props object before passing it to
1323
- * `createElement` or a factory, use `ClassAttributes<T>`:
1324
- *
1325
- * ```ts
1326
- * var b: Button | null;
1327
- * var props: ButtonProps & ClassAttributes<Button> = {
1328
- * ref: b => button = b, // ok!
1329
- * label: "I'm a Button"
1330
- * };
1331
- * ```
1332
- */
1333
- interface Props<T> {
1334
- children?: ReactNode | undefined;
1335
- key?: Key | undefined;
1336
- ref?: LegacyRef<T> | undefined;
1337
- }
1338
-
1339
1351
  interface HTMLProps<T> extends AllHTMLAttributes<T>, ClassAttributes<T> {
1340
1352
  }
1341
1353
 
react/next.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  /**
2
- * These are types for things that are present in the upcoming React 18 release.
3
- *
4
- * Once React 18 is released they can just be moved to the main index file.
2
+ * These are types for things that are present in the React `next` release channel.
5
3
  *
6
4
  * To load the types declared here in an actual project, there are three ways. The easiest one,
7
5
  * if your `tsconfig.json` already has a `"types"` array in the `"compilerOptions"` section,
@@ -23,126 +21,10 @@
23
21
  * Either the import or the reference only needs to appear once, anywhere in the project.
24
22
  */
25
23
 
26
- // See https://github.com/facebook/react/blob/master/packages/react/src/React.js to see how the exports are declared,
24
+ // See https://github.com/facebook/react/blob/main/packages/react/src/React.js to see how the exports are declared,
27
25
 
28
26
  import React = require('.');
29
27
 
30
28
  export {};
31
29
 
32
- declare const UNDEFINED_VOID_ONLY: unique symbol;
33
- type VoidOrUndefinedOnly = void | { [UNDEFINED_VOID_ONLY]: never };
34
-
35
- declare module '.' {
36
- export interface SuspenseProps {
37
- /**
38
- * The presence of this prop indicates that the content is computationally expensive to render.
39
- * In other words, the tree is CPU bound and not I/O bound (e.g. due to fetching data).
40
- * @see {@link https://github.com/facebook/react/pull/19936}
41
- */
42
- unstable_expectedLoadTime?: number | undefined;
43
- }
44
-
45
- // must be synchronous
46
- export type TransitionFunction = () => VoidOrUndefinedOnly;
47
- // strange definition to allow vscode to show documentation on the invocation
48
- export interface TransitionStartFunction {
49
- /**
50
- * State updates caused inside the callback are allowed to be deferred.
51
- *
52
- * **If some state update causes a component to suspend, that state update should be wrapped in a transition.**
53
- *
54
- * @param callback A _synchronous_ function which causes state updates that can be deferred.
55
- */
56
- (callback: TransitionFunction): void;
57
- }
58
-
59
- /**
60
- * Returns a deferred version of the value that may “lag behind” it for at most `timeoutMs`.
61
- *
62
- * This is commonly used to keep the interface responsive when you have something that renders immediately
63
- * based on user input and something that needs to wait for a data fetch.
64
- *
65
- * A good example of this is a text input.
66
- *
67
- * @param value The value that is going to be deferred
68
- *
69
- * @see https://reactjs.org/docs/concurrent-mode-reference.html#usedeferredvalue
70
- */
71
- export function useDeferredValue<T>(value: T): T;
72
-
73
- /**
74
- * Allows components to avoid undesirable loading states by waiting for content to load
75
- * before transitioning to the next screen. It also allows components to defer slower,
76
- * data fetching updates until subsequent renders so that more crucial updates can be
77
- * rendered immediately.
78
- *
79
- * The `useTransition` hook returns two values in an array.
80
- *
81
- * The first is a boolean, React’s way of informing us whether we’re waiting for the transition to finish.
82
- * The second is a function that takes a callback. We can use it to tell React which state we want to defer.
83
- *
84
- * **If some state update causes a component to suspend, that state update should be wrapped in a transition.**
85
- *
86
- * @param config An optional object with `timeoutMs`
87
- *
88
- * @see https://reactjs.org/docs/concurrent-mode-reference.html#usetransition
89
- */
90
- export function useTransition(): [boolean, TransitionStartFunction];
91
-
92
- /**
93
- * Similar to `useTransition` but allows uses where hooks are not available.
94
- *
95
- * @param callback A _synchronous_ function which causes state updates that can be deferred.
96
- */
97
- export function startTransition(scope: TransitionFunction): void;
98
-
99
- export function useId(): string;
100
-
101
- /**
102
- * this should be an internal type
103
- */
104
- interface MutableSource<T> {
105
- _source: T;
106
- }
107
-
108
- export type MutableSourceSubscribe<T> = (source: T, callback: () => void) => () => void;
109
-
110
- /**
111
- * @param source A source could be anything as long as they can be subscribed to and have a "version".
112
- * @param getVersion A function returns a value which will change whenever part of the source changes.
113
- */
114
- export function unstable_createMutableSource<T>(source: T, getVersion: () => any): MutableSource<T>;
115
-
116
- /**
117
- * useMutableSource() enables React components to safely and efficiently read from a mutable external source in Concurrent Mode.
118
- * The API will detect mutations that occur during a render to avoid tearing
119
- * and it will automatically schedule updates when the source is mutated.
120
- * @param MutableSource
121
- * @param getSnapshot
122
- * @param subscribe
123
- *
124
- * @see https://github.com/reactjs/rfcs/blob/master/text/0147-use-mutable-source.md
125
- */
126
- export function unstable_useMutableSource<T, TResult extends unknown>(MutableSource: MutableSource<T>, getSnapshot: (source: T) => TResult, subscribe: MutableSourceSubscribe<T>): TResult;
127
-
128
- /**
129
- * @param effect Imperative function that can return a cleanup function
130
- * @param deps If present, effect will only activate if the values in the list change.
131
- *
132
- * @see https://github.com/facebook/react/pull/21913
133
- */
134
- export function useInsertionEffect(effect: EffectCallback, deps?: DependencyList): void;
135
-
136
- /**
137
- * @param subscribe
138
- * @param getSnapshot
139
- *
140
- * @see https://github.com/reactwg/react-18/discussions/86
141
- */
142
- // keep in sync with `useSyncExternalStore` from `use-sync-external-store`
143
- export function useSyncExternalStore<Snapshot>(
144
- subscribe: (onStoreChange: () => void) => () => void,
145
- getSnapshot: () => Snapshot,
146
- getServerSnapshot?: () => Snapshot,
147
- ): Snapshot;
148
- }
30
+ declare module '.' {}
react/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@types/react",
3
- "version": "17.0.43",
3
+ "version": "18.0.1",
4
4
  "description": "TypeScript definitions for React",
5
5
  "homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react",
6
6
  "license": "MIT",
@@ -146,6 +146,6 @@
146
146
  "@types/scheduler": "*",
147
147
  "csstype": "^3.0.2"
148
148
  },
149
- "typesPublisherContentHash": "eb0438d4dbd7569f29ddd1f4d8ee8a7e294faa1c5259c584487708a81306cc32",
149
+ "typesPublisherContentHash": "ddc52aa6c78f2a2ba91aafa55259e3f26332caf113976b09811527f1f795c40a",
150
150
  "typeScriptVersion": "3.9"
151
151
  }