@docusaurus/module-type-aliases 2.0.0-beta.15a2b59f9 → 2.0.0-beta.17

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 +154 -70
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/module-type-aliases",
3
- "version": "2.0.0-beta.15a2b59f9",
3
+ "version": "2.0.0-beta.17",
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.17",
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": "34881586224092fb9b5b2f455a46e19b3eee7f08"
26
+ "gitHead": "0032c0b0480083227af2e1b4da2d3ee6ce992403"
23
27
  }
package/src/index.d.ts CHANGED
@@ -6,45 +6,58 @@
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 {DocusaurusSiteMetadata} from '@docusaurus/types';
24
+
25
+ const siteMetadata: DocusaurusSiteMetadata;
26
+ export = siteMetadata;
21
27
  }
22
28
 
23
29
  declare module '@generated/registry' {
24
30
  const registry: {
31
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
32
  readonly [key: string]: [() => Promise<any>, string, string];
26
33
  };
27
34
  export default registry;
28
35
  }
29
36
 
30
37
  declare module '@generated/routes' {
31
- type Route = {
38
+ import type {RouteConfig} from 'react-router-config';
39
+
40
+ export type Route = {
32
41
  readonly path: string;
33
- readonly component: any;
42
+ readonly component: RouteConfig['component'];
34
43
  readonly exact?: boolean;
44
+ readonly routes?: Route[];
35
45
  };
36
46
  const routes: Route[];
37
47
  export default routes;
38
48
  }
39
49
 
40
50
  declare module '@generated/routesChunkNames' {
41
- const routesChunkNames: Record<string, Record<string, string>>;
42
- export default routesChunkNames;
51
+ import type {RouteChunksTree} from '@docusaurus/types';
52
+
53
+ const routesChunkNames: Record<string, RouteChunksTree>;
54
+ export = routesChunkNames;
43
55
  }
44
56
 
45
57
  declare module '@generated/globalData' {
46
- const globalData: Record<string, unknown>;
47
- export default globalData;
58
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
+ const globalData: Record<string, any>;
60
+ export = globalData;
48
61
  }
49
62
 
50
63
  declare module '@generated/i18n' {
@@ -52,72 +65,127 @@ declare module '@generated/i18n' {
52
65
  defaultLocale: string;
53
66
  locales: [string, ...string[]];
54
67
  currentLocale: string;
55
- localeConfigs: Record<string, {label: string; direction: string}>;
68
+ localeConfigs: Record<
69
+ string,
70
+ {
71
+ label: string;
72
+ direction: string;
73
+ htmlLang: string;
74
+ }
75
+ >;
56
76
  };
57
- export default i18n;
77
+ export = i18n;
58
78
  }
59
79
 
60
80
  declare module '@generated/codeTranslations' {
61
81
  const codeTranslations: Record<string, string>;
62
- export default codeTranslations;
82
+ export = codeTranslations;
63
83
  }
64
84
 
65
- declare module '@theme/*';
66
-
67
85
  declare module '@theme-original/*';
86
+ declare module '@theme-init/*';
87
+
88
+ declare module '@theme/Error' {
89
+ export interface Props {
90
+ readonly error: Error;
91
+ readonly tryAgain: () => void;
92
+ }
93
+ export default function Error(props: Props): JSX.Element;
94
+ }
68
95
 
69
- declare module '@docusaurus/*';
96
+ declare module '@theme/Layout' {
97
+ import type {ReactNode} from 'react';
70
98
 
71
- declare module '@docusaurus/Head' {
72
- import type {HelmetProps} from 'react-helmet';
99
+ export interface Props {
100
+ readonly children?: ReactNode;
101
+ readonly title?: string;
102
+ readonly description?: string;
103
+ }
104
+ export default function Layout(props: Props): JSX.Element;
105
+ }
106
+
107
+ declare module '@theme/Loading' {
108
+ import type {LoadingComponentProps} from 'react-loadable';
109
+
110
+ export default function Loading(props: LoadingComponentProps): JSX.Element;
111
+ }
112
+
113
+ declare module '@theme/NotFound' {
114
+ export default function NotFound(): JSX.Element;
115
+ }
116
+
117
+ declare module '@theme/Root' {
73
118
  import type {ReactNode} from 'react';
74
119
 
75
- export type HeadProps = HelmetProps & {children: ReactNode};
120
+ export interface Props {
121
+ readonly children: ReactNode;
122
+ }
123
+ export default function Root({children}: Props): JSX.Element;
124
+ }
76
125
 
77
- const Head: (props: HeadProps) => JSX.Element;
78
- export default Head;
126
+ declare module '@docusaurus/constants' {
127
+ export const DEFAULT_PLUGIN_ID: 'default';
79
128
  }
80
129
 
81
- declare module '@docusaurus/Link' {
130
+ declare module '@docusaurus/ErrorBoundary' {
82
131
  import type {ReactNode} from 'react';
132
+ import type ErrorComponent from '@theme/Error';
83
133
 
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;
134
+ export interface Props {
135
+ readonly fallback?: typeof ErrorComponent;
136
+ readonly children: ReactNode;
137
+ }
138
+ export default function ErrorBoundary(props: Props): JSX.Element;
139
+ }
93
140
 
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;
141
+ declare module '@docusaurus/Head' {
142
+ import type {HelmetProps} from 'react-helmet-async';
143
+ import type {ReactNode} from 'react';
144
+
145
+ export type Props = HelmetProps & {children: ReactNode};
146
+
147
+ export default function Head(props: Props): JSX.Element;
148
+ }
149
+
150
+ declare module '@docusaurus/Link' {
151
+ import type {CSSProperties, ComponentProps} from 'react';
152
+
153
+ type NavLinkProps = Partial<import('react-router-dom').NavLinkProps>;
154
+ export type Props = NavLinkProps &
155
+ ComponentProps<'a'> & {
156
+ readonly className?: string;
157
+ readonly style?: CSSProperties;
158
+ readonly isNavLink?: boolean;
159
+ readonly to?: string;
160
+ readonly href?: string;
161
+ readonly autoAddBaseUrl?: boolean;
162
+
163
+ // escape hatch in case broken links check is annoying for a specific link
164
+ readonly 'data-noBrokenLinkCheck'?: boolean;
165
+ };
166
+ export default function Link(props: Props): JSX.Element;
99
167
  }
100
168
 
101
169
  declare module '@docusaurus/Interpolate' {
102
170
  import type {ReactNode} from 'react';
103
171
 
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;
172
+ export type ExtractInterpolatePlaceholders<Str extends string> =
173
+ Str extends `${string}{${infer Key}}${infer Rest}`
174
+ ? Key | ExtractInterpolatePlaceholders<Rest>
175
+ : never;
108
176
 
109
177
  export type InterpolateValues<
110
178
  Str extends string,
111
- Value extends ReactNode
179
+ Value extends ReactNode,
112
180
  > = Record<ExtractInterpolatePlaceholders<Str>, Value>;
113
181
 
114
- // TS function overload: if all the values are plain strings, then interpolate returns a simple string
182
+ // If all the values are plain strings, interpolate returns a simple string
115
183
  export function interpolate<Str extends string>(
116
184
  text: Str,
117
185
  values?: InterpolateValues<Str, string | number>,
118
186
  ): string;
119
187
 
120
- // If values contain any ReactNode, then the return is a ReactNode
188
+ // If values contain any ReactNode, the return is a ReactNode
121
189
  export function interpolate<Str extends string, Value extends ReactNode>(
122
190
  text: Str,
123
191
  values?: InterpolateValues<Str, Value>,
@@ -134,18 +202,23 @@ declare module '@docusaurus/Interpolate' {
134
202
  }
135
203
 
136
204
  declare module '@docusaurus/Translate' {
137
- import type {
138
- InterpolateProps,
139
- InterpolateValues,
140
- } from '@docusaurus/Interpolate';
205
+ import type {ReactNode} from 'react';
206
+ import type {InterpolateValues} from '@docusaurus/Interpolate';
141
207
 
142
- export type TranslateParam<Str extends string> = Partial<
143
- InterpolateProps<Str>
208
+ // TS type to ensure that at least one of id or message is always provided
209
+ // (Generic permits to handled message provided as React children)
210
+ type IdOrMessage<
211
+ MessageKey extends 'children' | 'message',
212
+ Str extends string,
213
+ > =
214
+ | ({[key in MessageKey]: Str} & {id?: string})
215
+ | ({[key in MessageKey]?: Str} & {id: string});
216
+
217
+ export type TranslateParam<Str extends string> = IdOrMessage<
218
+ 'message',
219
+ Str
144
220
  > & {
145
- message: Str;
146
- id?: string;
147
221
  description?: string;
148
- values?: InterpolateValues<Str, string | number>;
149
222
  };
150
223
 
151
224
  export function translate<Str extends string>(
@@ -153,9 +226,12 @@ declare module '@docusaurus/Translate' {
153
226
  values?: InterpolateValues<Str, string | number>,
154
227
  ): string;
155
228
 
156
- export type TranslateProps<Str extends string> = InterpolateProps<Str> & {
157
- id?: string;
229
+ export type TranslateProps<Str extends string> = IdOrMessage<
230
+ 'children',
231
+ Str
232
+ > & {
158
233
  description?: string;
234
+ values?: InterpolateValues<Str, ReactNode>;
159
235
  };
160
236
 
161
237
  export default function Translate<Str extends string>(
@@ -165,15 +241,17 @@ declare module '@docusaurus/Translate' {
165
241
 
166
242
  declare module '@docusaurus/router' {
167
243
  // eslint-disable-next-line import/no-extraneous-dependencies
168
- export * from 'react-router-dom';
169
- }
170
- declare module '@docusaurus/history' {
171
- // eslint-disable-next-line import/no-extraneous-dependencies
172
- export * from 'history';
244
+ export {useHistory, useLocation, Redirect, matchPath} from 'react-router-dom';
173
245
  }
174
246
 
175
247
  declare module '@docusaurus/useDocusaurusContext' {
176
- export default function (): any;
248
+ import type {DocusaurusContext} from '@docusaurus/types';
249
+
250
+ export default function useDocusaurusContext(): DocusaurusContext;
251
+ }
252
+
253
+ declare module '@docusaurus/useIsBrowser' {
254
+ export default function useIsBrowser(): boolean;
177
255
  }
178
256
 
179
257
  declare module '@docusaurus/useBaseUrl' {
@@ -207,20 +285,18 @@ declare module '@docusaurus/ExecutionEnvironment' {
207
285
  declare module '@docusaurus/ComponentCreator' {
208
286
  import type Loadable from 'react-loadable';
209
287
 
210
- function ComponentCreator(
288
+ export default function ComponentCreator(
211
289
  path: string,
212
290
  hash: string,
213
291
  ): ReturnType<typeof Loadable>;
214
- export default ComponentCreator;
215
292
  }
216
293
 
217
294
  declare module '@docusaurus/BrowserOnly' {
218
- export type Props = {
219
- children?: () => JSX.Element;
220
- fallback?: JSX.Element;
221
- };
222
- const BrowserOnly: (props: Props) => JSX.Element | null;
223
- export default BrowserOnly;
295
+ export interface Props {
296
+ readonly children?: () => JSX.Element;
297
+ readonly fallback?: JSX.Element;
298
+ }
299
+ export default function BrowserOnly(props: Props): JSX.Element | null;
224
300
  }
225
301
 
226
302
  declare module '@docusaurus/isInternalUrl' {
@@ -249,8 +325,16 @@ declare module '@docusaurus/useGlobalData' {
249
325
  pluginId?: string,
250
326
  ): T;
251
327
 
252
- function useGlobalData(): Record<string, any>;
253
- export default useGlobalData;
328
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
329
+ export default function useGlobalData(): Record<string, any>;
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;
254
338
  }
255
339
 
256
340
  declare module '*.module.css' {