@docusaurus/module-type-aliases 2.0.0-beta.1decd6f80 → 2.0.0-beta.20

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.
Files changed (2) hide show
  1. package/package.json +10 -6
  2. package/src/index.d.ts +180 -85
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/module-type-aliases",
3
- "version": "2.0.0-beta.1decd6f80",
3
+ "version": "2.0.0-beta.20",
4
4
  "description": "Docusaurus module type aliases.",
5
5
  "types": "./src/index.d.ts",
6
6
  "publishConfig": {
@@ -11,13 +11,17 @@
11
11
  "url": "https://github.com/facebook/docusaurus.git",
12
12
  "directory": "packages/docusaurus-module-type-aliases"
13
13
  },
14
- "devDependencies": {
14
+ "dependencies": {
15
+ "@docusaurus/types": "2.0.0-beta.20",
15
16
  "@types/react": "*",
16
- "@types/react-helmet": "*",
17
- "@types/react-loadable": "*",
18
17
  "@types/react-router-config": "*",
19
- "@types/react-router-dom": "*"
18
+ "@types/react-router-dom": "*",
19
+ "react-helmet-async": "*"
20
+ },
21
+ "peerDependencies": {
22
+ "react": "*",
23
+ "react-dom": "*"
20
24
  },
21
25
  "license": "MIT",
22
- "gitHead": "0f82d5997e05666fa8c0e8852e551c1a8ffe3876"
26
+ "gitHead": "ed5cdba401a5948e187e927039b142a0decc702d"
23
27
  }
package/src/index.d.ts CHANGED
@@ -6,118 +6,177 @@
6
6
  */
7
7
 
8
8
  declare module '@generated/client-modules' {
9
- const clientModules: readonly any[];
9
+ import type {ClientModule} from '@docusaurus/types';
10
+
11
+ const clientModules: readonly (ClientModule & {default: ClientModule})[];
10
12
  export default clientModules;
11
13
  }
12
14
 
13
15
  declare module '@generated/docusaurus.config' {
14
- const config: any;
16
+ import type {DocusaurusConfig} from '@docusaurus/types';
17
+
18
+ const config: DocusaurusConfig;
15
19
  export default config;
16
20
  }
17
21
 
18
22
  declare module '@generated/site-metadata' {
19
- const siteMetadata: any;
20
- export default siteMetadata;
23
+ import type {SiteMetadata} from '@docusaurus/types';
24
+
25
+ const siteMetadata: SiteMetadata;
26
+ export = siteMetadata;
21
27
  }
22
28
 
23
29
  declare module '@generated/registry' {
24
- const registry: {
25
- readonly [key: string]: [() => Promise<any>, string, string];
26
- };
30
+ import type {Registry} from '@docusaurus/types';
31
+
32
+ const registry: Registry;
27
33
  export default registry;
28
34
  }
29
35
 
30
36
  declare module '@generated/routes' {
31
- type Route = {
32
- readonly path: string;
33
- readonly component: any;
34
- readonly exact?: boolean;
37
+ import type {RouteConfig as RRRouteConfig} from 'react-router-config';
38
+
39
+ type RouteConfig = RRRouteConfig & {
40
+ path: string;
35
41
  };
36
- const routes: Route[];
42
+ const routes: RouteConfig[];
37
43
  export default routes;
38
44
  }
39
45
 
40
46
  declare module '@generated/routesChunkNames' {
41
- const routesChunkNames: Record<string, Record<string, string>>;
42
- export default routesChunkNames;
47
+ import type {RouteChunkNames} from '@docusaurus/types';
48
+
49
+ const routesChunkNames: RouteChunkNames;
50
+ export = routesChunkNames;
43
51
  }
44
52
 
45
53
  declare module '@generated/globalData' {
46
- const globalData: Record<string, unknown>;
47
- export default globalData;
54
+ import type {GlobalData} from '@docusaurus/types';
55
+
56
+ const globalData: GlobalData;
57
+ export = globalData;
48
58
  }
49
59
 
50
60
  declare module '@generated/i18n' {
51
- const i18n: {
52
- defaultLocale: string;
53
- locales: [string, ...string[]];
54
- currentLocale: string;
55
- localeConfigs: Record<string, {label: string; direction: string}>;
56
- };
57
- export default i18n;
61
+ import type {I18n} from '@docusaurus/types';
62
+
63
+ const i18n: I18n;
64
+ export = i18n;
58
65
  }
59
66
 
60
67
  declare module '@generated/codeTranslations' {
61
- const codeTranslations: Record<string, string>;
62
- export default codeTranslations;
63
- }
68
+ import type {CodeTranslations} from '@docusaurus/types';
64
69
 
65
- declare module '@theme/*';
70
+ const codeTranslations: CodeTranslations;
71
+ export = codeTranslations;
72
+ }
66
73
 
67
74
  declare module '@theme-original/*';
75
+ declare module '@theme-init/*';
76
+
77
+ declare module '@theme/Error' {
78
+ export interface Props {
79
+ readonly error: Error;
80
+ readonly tryAgain: () => void;
81
+ }
82
+ export default function Error(props: Props): JSX.Element;
83
+ }
68
84
 
69
- declare module '@docusaurus/*';
85
+ declare module '@theme/Layout' {
86
+ import type {ReactNode} from 'react';
70
87
 
71
- declare module '@docusaurus/Head' {
72
- import type {HelmetProps} from 'react-helmet';
88
+ export interface Props {
89
+ readonly children?: ReactNode;
90
+ }
91
+ export default function Layout(props: Props): JSX.Element;
92
+ }
93
+
94
+ declare module '@theme/Loading' {
95
+ import type {LoadingComponentProps} from 'react-loadable';
96
+
97
+ export default function Loading(props: LoadingComponentProps): JSX.Element;
98
+ }
99
+
100
+ declare module '@theme/NotFound' {
101
+ export default function NotFound(): JSX.Element;
102
+ }
103
+
104
+ declare module '@theme/Root' {
73
105
  import type {ReactNode} from 'react';
74
106
 
75
- export type HeadProps = HelmetProps & {children: ReactNode};
107
+ export interface Props {
108
+ readonly children: ReactNode;
109
+ }
110
+ export default function Root({children}: Props): JSX.Element;
111
+ }
76
112
 
77
- const Head: (props: HeadProps) => JSX.Element;
78
- export default Head;
113
+ declare module '@theme/SiteMetadata' {
114
+ export default function SiteMetadata(): JSX.Element;
79
115
  }
80
116
 
81
- declare module '@docusaurus/Link' {
117
+ declare module '@docusaurus/constants' {
118
+ export const DEFAULT_PLUGIN_ID: 'default';
119
+ }
120
+
121
+ declare module '@docusaurus/ErrorBoundary' {
82
122
  import type {ReactNode} from 'react';
123
+ import type ErrorComponent from '@theme/Error';
83
124
 
84
- type RRLinkProps = Partial<import('react-router-dom').LinkProps>;
85
- export type LinkProps = RRLinkProps & {
86
- readonly isNavLink?: boolean;
87
- readonly to?: string;
88
- readonly href?: string;
89
- readonly activeClassName?: string;
90
- readonly children?: ReactNode;
91
- readonly isActive?: (match: any, location: any) => boolean;
92
- readonly autoAddBaseUrl?: boolean;
125
+ export interface Props {
126
+ readonly fallback?: typeof ErrorComponent;
127
+ readonly children: ReactNode;
128
+ }
129
+ export default function ErrorBoundary(props: Props): JSX.Element;
130
+ }
93
131
 
94
- // escape hatch in case broken links check is annoying for a specific link
95
- readonly 'data-noBrokenLinkCheck'?: boolean;
96
- };
97
- const Link: (props: LinkProps) => JSX.Element;
98
- export default Link;
132
+ declare module '@docusaurus/Head' {
133
+ import type {HelmetProps} from 'react-helmet-async';
134
+ import type {ReactNode} from 'react';
135
+
136
+ export type Props = HelmetProps & {children: ReactNode};
137
+
138
+ export default function Head(props: Props): JSX.Element;
139
+ }
140
+
141
+ declare module '@docusaurus/Link' {
142
+ import type {CSSProperties, ComponentProps} from 'react';
143
+ import type {NavLinkProps as RRNavLinkProps} from 'react-router-dom';
144
+
145
+ type NavLinkProps = Partial<RRNavLinkProps>;
146
+ export type Props = NavLinkProps &
147
+ ComponentProps<'a'> & {
148
+ readonly className?: string;
149
+ readonly style?: CSSProperties;
150
+ readonly isNavLink?: boolean;
151
+ readonly to?: string;
152
+ readonly href?: string;
153
+ readonly autoAddBaseUrl?: boolean;
154
+
155
+ /** Escape hatch in case broken links check doesn't make sense. */
156
+ readonly 'data-noBrokenLinkCheck'?: boolean;
157
+ };
158
+ export default function Link(props: Props): JSX.Element;
99
159
  }
100
160
 
101
161
  declare module '@docusaurus/Interpolate' {
102
162
  import type {ReactNode} from 'react';
103
163
 
104
- // TODO use TS template literal feature to make values typesafe!
105
- // (requires upgrading TS first)
106
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
107
- export type ExtractInterpolatePlaceholders<Str extends string> = string;
164
+ export type ExtractInterpolatePlaceholders<Str extends string> =
165
+ Str extends `${string}{${infer Key}}${infer Rest}`
166
+ ? Key | ExtractInterpolatePlaceholders<Rest>
167
+ : never;
108
168
 
109
- export type InterpolateValues<
110
- Str extends string,
111
- Value extends ReactNode
112
- > = Record<ExtractInterpolatePlaceholders<Str>, Value>;
169
+ export type InterpolateValues<Str extends string, Value extends ReactNode> = {
170
+ [key in ExtractInterpolatePlaceholders<Str>]: Value;
171
+ };
113
172
 
114
- // TS function overload: if all the values are plain strings, then interpolate returns a simple string
173
+ // If all the values are plain strings, interpolate returns a simple string
115
174
  export function interpolate<Str extends string>(
116
175
  text: Str,
117
176
  values?: InterpolateValues<Str, string | number>,
118
177
  ): string;
119
178
 
120
- // If values contain any ReactNode, then the return is a ReactNode
179
+ // If values contain any ReactNode, the return is a ReactNode
121
180
  export function interpolate<Str extends string, Value extends ReactNode>(
122
181
  text: Str,
123
182
  values?: InterpolateValues<Str, Value>,
@@ -134,18 +193,23 @@ declare module '@docusaurus/Interpolate' {
134
193
  }
135
194
 
136
195
  declare module '@docusaurus/Translate' {
137
- import type {
138
- InterpolateProps,
139
- InterpolateValues,
140
- } from '@docusaurus/Interpolate';
196
+ import type {ReactNode} from 'react';
197
+ import type {InterpolateValues} from '@docusaurus/Interpolate';
198
+
199
+ // TS type to ensure that at least one of id or message is always provided
200
+ // (Generic permits to handled message provided as React children)
201
+ type IdOrMessage<
202
+ MessageKey extends 'children' | 'message',
203
+ Str extends string,
204
+ > =
205
+ | ({[key in MessageKey]: Str} & {id?: string})
206
+ | ({[key in MessageKey]?: Str} & {id: string});
141
207
 
142
- export type TranslateParam<Str extends string> = Partial<
143
- InterpolateProps<Str>
208
+ export type TranslateParam<Str extends string> = IdOrMessage<
209
+ 'message',
210
+ Str
144
211
  > & {
145
- message: Str;
146
- id?: string;
147
212
  description?: string;
148
- values?: InterpolateValues<Str, string | number>;
149
213
  };
150
214
 
151
215
  export function translate<Str extends string>(
@@ -153,9 +217,12 @@ declare module '@docusaurus/Translate' {
153
217
  values?: InterpolateValues<Str, string | number>,
154
218
  ): string;
155
219
 
156
- export type TranslateProps<Str extends string> = InterpolateProps<Str> & {
157
- id?: string;
220
+ export type TranslateProps<Str extends string> = IdOrMessage<
221
+ 'children',
222
+ Str
223
+ > & {
158
224
  description?: string;
225
+ values?: InterpolateValues<Str, ReactNode>;
159
226
  };
160
227
 
161
228
  export default function Translate<Str extends string>(
@@ -165,11 +232,23 @@ declare module '@docusaurus/Translate' {
165
232
 
166
233
  declare module '@docusaurus/router' {
167
234
  // eslint-disable-next-line import/no-extraneous-dependencies
168
- export * from 'react-router-dom';
235
+ export {useHistory, useLocation, Redirect, matchPath} from 'react-router-dom';
169
236
  }
170
237
 
171
238
  declare module '@docusaurus/useDocusaurusContext' {
172
- export default function (): any;
239
+ import type {DocusaurusContext} from '@docusaurus/types';
240
+
241
+ export default function useDocusaurusContext(): DocusaurusContext;
242
+ }
243
+
244
+ declare module '@docusaurus/useRouteContext' {
245
+ import type {PluginRouteContext} from '@docusaurus/types';
246
+
247
+ export default function useRouteContext(): PluginRouteContext;
248
+ }
249
+
250
+ declare module '@docusaurus/useIsBrowser' {
251
+ export default function useIsBrowser(): boolean;
173
252
  }
174
253
 
175
254
  declare module '@docusaurus/useBaseUrl' {
@@ -203,20 +282,18 @@ declare module '@docusaurus/ExecutionEnvironment' {
203
282
  declare module '@docusaurus/ComponentCreator' {
204
283
  import type Loadable from 'react-loadable';
205
284
 
206
- function ComponentCreator(
285
+ export default function ComponentCreator(
207
286
  path: string,
208
287
  hash: string,
209
288
  ): ReturnType<typeof Loadable>;
210
- export default ComponentCreator;
211
289
  }
212
290
 
213
291
  declare module '@docusaurus/BrowserOnly' {
214
- export type Props = {
215
- children?: () => JSX.Element;
216
- fallback?: JSX.Element;
217
- };
218
- const BrowserOnly: (props: Props) => JSX.Element | null;
219
- export default BrowserOnly;
292
+ export interface Props {
293
+ readonly children?: () => JSX.Element;
294
+ readonly fallback?: JSX.Element;
295
+ }
296
+ export default function BrowserOnly(props: Props): JSX.Element | null;
220
297
  }
221
298
 
222
299
  declare module '@docusaurus/isInternalUrl' {
@@ -236,17 +313,28 @@ declare module '@docusaurus/renderRoutes' {
236
313
  }
237
314
 
238
315
  declare module '@docusaurus/useGlobalData' {
239
- export function useAllPluginInstancesData<T = unknown>(
316
+ import type {GlobalData, UseDataOptions} from '@docusaurus/types';
317
+
318
+ export function useAllPluginInstancesData(
240
319
  pluginName: string,
241
- ): Record<string, T>;
320
+ options?: UseDataOptions,
321
+ ): GlobalData[string] | undefined;
242
322
 
243
- export function usePluginData<T = unknown>(
323
+ export function usePluginData(
244
324
  pluginName: string,
245
325
  pluginId?: string,
246
- ): T;
326
+ options?: UseDataOptions,
327
+ ): GlobalData[string][string] | undefined;
247
328
 
248
- function useGlobalData(): Record<string, any>;
249
- export default useGlobalData;
329
+ export default function useGlobalData(): GlobalData;
330
+ }
331
+
332
+ declare module '*.svg' {
333
+ import type {ComponentType, SVGProps} from 'react';
334
+
335
+ const ReactComponent: ComponentType<SVGProps<SVGSVGElement>>;
336
+
337
+ export default ReactComponent;
250
338
  }
251
339
 
252
340
  declare module '*.module.css' {
@@ -258,3 +346,10 @@ declare module '*.css' {
258
346
  const src: string;
259
347
  export default src;
260
348
  }
349
+
350
+ interface Window {
351
+ docusaurus: {
352
+ prefetch: (url: string) => false | Promise<void[]>;
353
+ preload: (url: string) => false | Promise<void[]>;
354
+ };
355
+ }