diff --git a/packages/docusaurus-plugin-pwa/src/index.ts b/packages/docusaurus-plugin-pwa/src/index.ts index fa94328d28..368fc5e9cb 100644 --- a/packages/docusaurus-plugin-pwa/src/index.ts +++ b/packages/docusaurus-plugin-pwa/src/index.ts @@ -189,8 +189,7 @@ export default function pluginPWA( '**/*.{js,json,css,html}', '**/*.{png,jpg,jpeg,gif,svg,ico}', '**/*.{woff,woff2,eot,ttf,otf}', - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore + // @ts-expect-error: internal API? ...(injectManifest.globPatterns ?? []), ], // those attributes are not overrideable diff --git a/packages/docusaurus-types/src/index.d.ts b/packages/docusaurus-types/src/index.d.ts index d59184c98b..2bd60a9f7a 100644 --- a/packages/docusaurus-types/src/index.d.ts +++ b/packages/docusaurus-types/src/index.d.ts @@ -226,18 +226,15 @@ export interface Props extends LoadContext, InjectedHtmlTags { export interface PluginContentLoadedActions { addRoute: (config: RouteConfig) => void; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - createData: (name: string, data: any) => Promise; + createData: (name: string, data: string) => Promise; setGlobalData: (data: T) => void; } -export type AllContent = Record< - string, // plugin name - Record< - string, // plugin id - unknown // plugin data - > ->; +export type AllContent = { + [pluginName: string]: { + [pluginID: string]: unknown; + }; +}; // TODO improve type (not exposed by postcss-loader) export type PostCssOptions = Record & {plugins: unknown[]}; @@ -245,12 +242,11 @@ export type PostCssOptions = Record & {plugins: unknown[]}; export interface Plugin { name: string; loadContent?: () => Promise; - contentLoaded?: ({ - content, - actions, - }: { - content: Content; // the content loaded by this plugin instance - allContent: AllContent; // content loaded by ALL the plugins + contentLoaded?: (args: { + /** the content loaded by this plugin instance */ + content: Content; // + /** content loaded by ALL the plugins */ + allContent: AllContent; actions: PluginContentLoadedActions; }) => Promise; routesLoaded?: (routes: RouteConfig[]) => void; // TODO remove soon, deprecated (alpha-60) @@ -269,7 +265,7 @@ export interface Plugin { getPathsToWatch?: () => string[]; getClientModules?: () => string[]; extendCli?: (cli: CommanderStatic) => void; - injectHtmlTags?: ({content}: {content: Content}) => { + injectHtmlTags?: (args: {content: Content}) => { headTags?: HtmlTags; preBodyTags?: HtmlTags; postBodyTags?: HtmlTags; @@ -277,28 +273,13 @@ export interface Plugin { // TODO before/afterDevServer implementation // translations - getTranslationFiles?: ({ - content, - }: { - content: Content; - }) => Promise; - getDefaultCodeTranslationMessages?: () => Promise< - Record< - string, // id - string // message - > - >; - translateContent?: ({ - content, - translationFiles, - }: { + getTranslationFiles?: (args: {content: Content}) => Promise; + getDefaultCodeTranslationMessages?: () => Promise<{[id: string]: string}>; + translateContent?: (args: { content: Content; // the content loaded by this plugin instance translationFiles: TranslationFiles; }) => Content; - translateThemeConfig?: ({ - themeConfig, - translationFiles, - }: { + translateThemeConfig?: (args: { themeConfig: ThemeConfig; translationFiles: TranslationFiles; }) => ThemeConfig; diff --git a/packages/docusaurus/src/client/preload.ts b/packages/docusaurus/src/client/preload.ts index b81d54e62d..09405b4524 100644 --- a/packages/docusaurus/src/client/preload.ts +++ b/packages/docusaurus/src/client/preload.ts @@ -23,16 +23,7 @@ export default function preload( const matches = matchRoutes(routes, pathname); return Promise.all( - matches.map((match) => { - const {component} = match.route; - - // @ts-expect-error: ComponentCreator injected this method. - if (component && component.preload) { - // @ts-expect-error: checked above. - return component.preload(); - } - - return undefined; - }), + // @ts-expect-error: ComponentCreator injected this method. + matches.map((match) => match.route.component?.preload?.()), ); } diff --git a/packages/docusaurus/src/webpack/utils.ts b/packages/docusaurus/src/webpack/utils.ts index 2e3f868e6f..14568c890d 100644 --- a/packages/docusaurus/src/webpack/utils.ts +++ b/packages/docusaurus/src/webpack/utils.ts @@ -236,15 +236,20 @@ export function applyConfigurePostCss( return config; } +declare global { + interface Error { + /** @see https://webpack.js.org/api/node/#error-handling */ + details: unknown; + } +} + export function compile(config: Configuration[]): Promise { return new Promise((resolve, reject) => { const compiler = webpack(config); compiler.run((err, stats) => { if (err) { logger.error(err.stack || err); - // @ts-expect-error: see https://webpack.js.org/api/node/#error-handling if (err.details) { - // @ts-expect-error: see https://webpack.js.org/api/node/#error-handling logger.error(err.details); } reject(err);