UNPKG

2.94 kBTypeScriptView Raw
1/**
2 * These are types for things that are present in the React `next` release channel.
3 *
4 * To load the types declared here in an actual project, there are three ways. The easiest one,
5 * if your `tsconfig.json` already has a `"types"` array in the `"compilerOptions"` section,
6 * is to add `"react/next"` to the `"types"` array.
7 *
8 * Alternatively, a specific import syntax can to be used from a typescript file.
9 * This module does not exist in reality, which is why the {} is important:
10 *
11 * ```ts
12 * import {} from 'react/next'
13 * ```
14 *
15 * It is also possible to include it through a triple-slash reference:
16 *
17 * ```ts
18 * /// <reference types="react/next" />
19 * ```
20 *
21 * Either the import or the reference only needs to appear once, anywhere in the project.
22 */
23
24// See https://github.com/facebook/react/blob/main/packages/react/src/React.js to see how the exports are declared,
25
26import React = require('.');
27
28export {};
29
30declare module '.' {
31 interface ThenableImpl<T> {
32 then(onFulfill: (value: T) => unknown, onReject: (error: unknown) => unknown): void | PromiseLike<unknown>;
33 }
34 interface UntrackedThenable<T> extends ThenableImpl<T> {
35 status?: void;
36 }
37
38 export interface PendingThenable<T> extends ThenableImpl<T> {
39 status: 'pending';
40 }
41
42 export interface FulfilledThenable<T> extends ThenableImpl<T> {
43 status: 'fulfilled';
44 value: T;
45 }
46
47 export interface RejectedThenable<T> extends ThenableImpl<T> {
48 status: 'rejected';
49 reason: unknown;
50 }
51
52 export type Thenable<T> = UntrackedThenable<T> | PendingThenable<T> | FulfilledThenable<T> | RejectedThenable<T>;
53
54 export type Usable<T> = Thenable<T> | Context<T>;
55
56 export function use<T>(usable: Usable<T>): T;
57
58 interface ServerContextJSONArray extends ReadonlyArray<ServerContextJSONArray> {}
59 export type ServerContextJSONValue =
60 | string
61 | boolean
62 | number
63 | null
64 | ServerContextJSONArray
65 | { [key: string]: ServerContextJSONValue };
66 export interface ServerContext<T extends ServerContextJSONValue> {
67 Provider: Provider<T>;
68 }
69 /**
70 * Accepts a context object (the value returned from `React.createContext` or `React.createServerContext`) and returns the current
71 * context value, as given by the nearest context provider for the given context.
72 *
73 * @version 16.8.0
74 * @see https://reactjs.org/docs/hooks-reference.html#usecontext
75 */
76 function useContext<T extends ServerContextJSONValue>(context: ServerContext<T>): T;
77 export function createServerContext<T extends ServerContextJSONValue>(
78 globalName: string,
79 defaultValue: T,
80 ): ServerContext<T>;
81
82 // tslint:disable-next-line ban-types
83 export function cache<CachedFunction extends Function>(fn: CachedFunction): CachedFunction;
84
85 export function unstable_useCacheRefresh(): () => void;
86}