@docusaurus/module-type-aliases 2.0.0-beta.15d451942 → 2.0.0-beta.18

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