1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  * @flow
    
  8.  */
    
  9. 
    
  10. export type ReactNode =
    
  11.   | React$Element<any>
    
  12.   | ReactPortal
    
  13.   | ReactText
    
  14.   | ReactFragment
    
  15.   | ReactProvider<any>
    
  16.   | ReactConsumer<any>;
    
  17. 
    
  18. export type ReactEmpty = null | void | boolean;
    
  19. 
    
  20. export type ReactFragment = ReactEmpty | Iterable<React$Node>;
    
  21. 
    
  22. export type ReactNodeList = ReactEmpty | React$Node;
    
  23. 
    
  24. export type ReactText = string | number;
    
  25. 
    
  26. export type ReactProvider<T> = {
    
  27.   $$typeof: symbol | number,
    
  28.   type: ReactProviderType<T>,
    
  29.   key: null | string,
    
  30.   ref: null,
    
  31.   props: {
    
  32.     value: T,
    
  33.     children?: ReactNodeList,
    
  34.     ...
    
  35.   },
    
  36.   ...
    
  37. };
    
  38. 
    
  39. export type ReactProviderType<T> = {
    
  40.   $$typeof: symbol | number,
    
  41.   _context: ReactContext<T>,
    
  42.   ...
    
  43. };
    
  44. 
    
  45. export type ReactConsumer<T> = {
    
  46.   $$typeof: symbol | number,
    
  47.   type: ReactContext<T>,
    
  48.   key: null | string,
    
  49.   ref: null,
    
  50.   props: {
    
  51.     children: (value: T) => ReactNodeList,
    
  52.     ...
    
  53.   },
    
  54.   ...
    
  55. };
    
  56. 
    
  57. export type ReactContext<T> = {
    
  58.   $$typeof: symbol | number,
    
  59.   Consumer: ReactContext<T>,
    
  60.   Provider: ReactProviderType<T>,
    
  61.   _currentValue: T,
    
  62.   _currentValue2: T,
    
  63.   _threadCount: number,
    
  64.   // DEV only
    
  65.   _currentRenderer?: Object | null,
    
  66.   _currentRenderer2?: Object | null,
    
  67.   // This value may be added by application code
    
  68.   // to improve DEV tooling display names
    
  69.   displayName?: string,
    
  70. 
    
  71.   // only used by ServerContext
    
  72.   _defaultValue: T,
    
  73.   _globalName: string,
    
  74.   ...
    
  75. };
    
  76. 
    
  77. export type ServerContextJSONValue =
    
  78.   | string
    
  79.   | boolean
    
  80.   | number
    
  81.   | null
    
  82.   | $ReadOnlyArray<ServerContextJSONValue>
    
  83.   | {+[key: string]: ServerContextJSONValue};
    
  84. 
    
  85. export type ReactServerContext<T: any> = ReactContext<T>;
    
  86. 
    
  87. export type ReactPortal = {
    
  88.   $$typeof: symbol | number,
    
  89.   key: null | string,
    
  90.   containerInfo: any,
    
  91.   children: ReactNodeList,
    
  92.   // TODO: figure out the API for cross-renderer implementation.
    
  93.   implementation: any,
    
  94.   ...
    
  95. };
    
  96. 
    
  97. export type RefObject = {
    
  98.   current: any,
    
  99. };
    
  100. 
    
  101. export type ReactScope = {
    
  102.   $$typeof: symbol | number,
    
  103. };
    
  104. 
    
  105. export type ReactScopeQuery = (
    
  106.   type: string,
    
  107.   props: {[string]: mixed, ...},
    
  108.   instance: mixed,
    
  109. ) => boolean;
    
  110. 
    
  111. export type ReactScopeInstance = {
    
  112.   DO_NOT_USE_queryAllNodes(ReactScopeQuery): null | Array<Object>,
    
  113.   DO_NOT_USE_queryFirstNode(ReactScopeQuery): null | Object,
    
  114.   containsNode(Object): boolean,
    
  115.   getChildContextValues: <T>(context: ReactContext<T>) => Array<T>,
    
  116. };
    
  117. 
    
  118. // The subset of a Thenable required by things thrown by Suspense.
    
  119. // This doesn't require a value to be passed to either handler.
    
  120. export interface Wakeable {
    
  121.   then(onFulfill: () => mixed, onReject: () => mixed): void | Wakeable;
    
  122. }
    
  123. 
    
  124. // The subset of a Promise that React APIs rely on. This resolves a value.
    
  125. // This doesn't require a return value neither from the handler nor the
    
  126. // then function.
    
  127. interface ThenableImpl<T> {
    
  128.   then(
    
  129.     onFulfill: (value: T) => mixed,
    
  130.     onReject: (error: mixed) => mixed,
    
  131.   ): void | Wakeable;
    
  132. }
    
  133. interface UntrackedThenable<T> extends ThenableImpl<T> {
    
  134.   status?: void;
    
  135. }
    
  136. 
    
  137. export interface PendingThenable<T> extends ThenableImpl<T> {
    
  138.   status: 'pending';
    
  139. }
    
  140. 
    
  141. export interface FulfilledThenable<T> extends ThenableImpl<T> {
    
  142.   status: 'fulfilled';
    
  143.   value: T;
    
  144. }
    
  145. 
    
  146. export interface RejectedThenable<T> extends ThenableImpl<T> {
    
  147.   status: 'rejected';
    
  148.   reason: mixed;
    
  149. }
    
  150. 
    
  151. export type Thenable<T> =
    
  152.   | UntrackedThenable<T>
    
  153.   | PendingThenable<T>
    
  154.   | FulfilledThenable<T>
    
  155.   | RejectedThenable<T>;
    
  156. 
    
  157. export type OffscreenMode =
    
  158.   | 'hidden'
    
  159.   | 'unstable-defer-without-hiding'
    
  160.   | 'visible'
    
  161.   | 'manual';
    
  162. 
    
  163. export type StartTransitionOptions = {
    
  164.   name?: string,
    
  165. };
    
  166. 
    
  167. export type Usable<T> = Thenable<T> | ReactContext<T>;
    
  168. 
    
  169. export type ReactCustomFormAction = {
    
  170.   name?: string,
    
  171.   action?: string,
    
  172.   encType?: string,
    
  173.   method?: string,
    
  174.   target?: string,
    
  175.   data?: null | FormData,
    
  176. };
    
  177. 
    
  178. // This is an opaque type returned by decodeFormState on the server, but it's
    
  179. // defined in this shared file because the same type is used by React on
    
  180. // the client.
    
  181. export type ReactFormState<S, ReferenceId> = [
    
  182.   S /* actual state value */,
    
  183.   string /* key path */,
    
  184.   ReferenceId /* Server Reference ID */,
    
  185.   number /* number of bound arguments */,
    
  186. ];
    
  187. 
    
  188. export type Awaited<T> = T extends null | void
    
  189.   ? T // special case for `null | undefined` when not in `--strictNullChecks` mode
    
  190.   : T extends Object // `await` only unwraps object types with a callable then. Non-object types are not unwrapped.
    
  191.   ? T extends {then(onfulfilled: infer F): any} // thenable, extracts the first argument to `then()`
    
  192.     ? F extends (value: infer V) => any // if the argument to `then` is callable, extracts the argument
    
  193.       ? Awaited<V> // recursively unwrap the value
    
  194.       : empty // the argument to `then` was not callable.
    
  195.     : T // argument was not an object
    
  196.   : T; // non-thenable