UNPKG

6.43 kBTypeScriptView Raw
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.
5 *
6 * To load the types declared here in an actual project, there are three ways. The easiest one,
7 * if your `tsconfig.json` already has a `"types"` array in the `"compilerOptions"` section,
8 * is to add `"react-dom/canary"` to the `"types"` array.
9 *
10 * Alternatively, a specific import syntax can to be used from a typescript file.
11 * This module does not exist in reality, which is why the {} is important:
12 *
13 * ```ts
14 * import {} from 'react-dom/canary'
15 * ```
16 *
17 * It is also possible to include it through a triple-slash reference:
18 *
19 * ```ts
20 * /// <reference types="react-dom/canary" />
21 * ```
22 *
23 * Either the import or the reference only needs to appear once, anywhere in the project.
24 */
25
26// See https://github.com/facebook/react/blob/main/packages/react-dom/index.js to see how the exports are declared,
27// but confirm with published source code (e.g. https://unpkg.com/react-dom@canary) that these exports end up in the published code
28
29import React = require("react");
30import ReactDOM = require(".");
31
32export {};
33
34declare const REACT_FORM_STATE_SIGIL: unique symbol;
35
36declare module "." {
37 function prefetchDNS(href: string): void;
38
39 interface PreconnectOptions {
40 // Don't create a helper type.
41 // It would have to be in module scope to be inlined in TS tooltips.
42 // But then it becomes part of the public API.
43 // TODO: Upstream to microsoft/TypeScript-DOM-lib-generator -> w3c/webref
44 // since the spec has a notion of a dedicated type: https://html.spec.whatwg.org/multipage/urls-and-fetching.html#cors-settings-attribute
45 crossOrigin?: "anonymous" | "use-credentials" | "" | undefined;
46 }
47 function preconnect(href: string, options?: PreconnectOptions): void;
48
49 type PreloadAs =
50 | "audio"
51 | "document"
52 | "embed"
53 | "fetch"
54 | "font"
55 | "image"
56 | "object"
57 | "track"
58 | "script"
59 | "style"
60 | "video"
61 | "worker";
62 interface PreloadOptions {
63 as: PreloadAs;
64 crossOrigin?: "anonymous" | "use-credentials" | "" | undefined;
65 fetchPriority?: "high" | "low" | "auto" | undefined;
66 // TODO: These should only be allowed with `as: 'image'` but it's not trivial to write tests against the full TS support matrix.
67 imageSizes?: string | undefined;
68 imageSrcSet?: string | undefined;
69 integrity?: string | undefined;
70 type?: string | undefined;
71 nonce?: string | undefined;
72 referrerPolicy?: ReferrerPolicy | undefined;
73 }
74 function preload(href: string, options?: PreloadOptions): void;
75
76 // https://html.spec.whatwg.org/multipage/links.html#link-type-modulepreload
77 type PreloadModuleAs = RequestDestination;
78 interface PreloadModuleOptions {
79 /**
80 * @default "script"
81 */
82 as: PreloadModuleAs;
83 crossOrigin?: "anonymous" | "use-credentials" | "" | undefined;
84 integrity?: string | undefined;
85 nonce?: string | undefined;
86 }
87 function preloadModule(href: string, options?: PreloadModuleOptions): void;
88
89 type PreinitAs = "script" | "style";
90 interface PreinitOptions {
91 as: PreinitAs;
92 crossOrigin?: "anonymous" | "use-credentials" | "" | undefined;
93 fetchPriority?: "high" | "low" | "auto" | undefined;
94 precedence?: string | undefined;
95 integrity?: string | undefined;
96 nonce?: string | undefined;
97 }
98 function preinit(href: string, options?: PreinitOptions): void;
99
100 // Will be expanded to include all of https://github.com/tc39/proposal-import-attributes
101 type PreinitModuleAs = "script";
102 interface PreinitModuleOptions {
103 /**
104 * @default "script"
105 */
106 as?: PreinitModuleAs;
107 crossOrigin?: "anonymous" | "use-credentials" | "" | undefined;
108 integrity?: string | undefined;
109 nonce?: string | undefined;
110 }
111 function preinitModule(href: string, options?: PreinitModuleOptions): void;
112
113 interface FormStatusNotPending {
114 pending: false;
115 data: null;
116 method: null;
117 action: null;
118 }
119
120 interface FormStatusPending {
121 pending: true;
122 data: FormData;
123 method: string;
124 action: string | ((formData: FormData) => void | Promise<void>);
125 }
126
127 type FormStatus = FormStatusPending | FormStatusNotPending;
128
129 function useFormStatus(): FormStatus;
130
131 function useFormState<State>(
132 action: (state: Awaited<State>) => State | Promise<State>,
133 initialState: Awaited<State>,
134 permalink?: string,
135 ): [state: Awaited<State>, dispatch: () => void, isPending: boolean];
136 function useFormState<State, Payload>(
137 action: (state: Awaited<State>, payload: Payload) => State | Promise<State>,
138 initialState: Awaited<State>,
139 permalink?: string,
140 ): [state: Awaited<State>, dispatch: (payload: Payload) => void, isPending: boolean];
141
142 function requestFormReset(form: HTMLFormElement): void;
143}
144
145declare module "./client" {
146 interface ReactFormState {
147 [REACT_FORM_STATE_SIGIL]: never;
148 }
149
150 interface RootOptions {
151 onUncaughtError?:
152 | ((error: unknown, errorInfo: { componentStack?: string | undefined }) => void)
153 | undefined;
154 onCaughtError?:
155 | ((
156 error: unknown,
157 errorInfo: {
158 componentStack?: string | undefined;
159 errorBoundary?: React.Component<unknown> | undefined;
160 },
161 ) => void)
162 | undefined;
163 }
164
165 interface HydrationOptions {
166 formState?: ReactFormState | null;
167 onUncaughtError?:
168 | ((error: unknown, errorInfo: { componentStack?: string | undefined }) => void)
169 | undefined;
170 onCaughtError?:
171 | ((
172 error: unknown,
173 errorInfo: {
174 componentStack?: string | undefined;
175 errorBoundary?: React.Component<unknown> | undefined;
176 },
177 ) => void)
178 | undefined;
179 }
180
181 interface DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_CREATE_ROOT_CONTAINERS {
182 document: Document;
183 }
184}
185
\No newline at end of file