diff --git a/packages/docusaurus-mdx-loader/src/deps.d.ts b/packages/docusaurus-mdx-loader/src/deps.d.ts index f4adca18b3c8..510bfc74e092 100644 --- a/packages/docusaurus-mdx-loader/src/deps.d.ts +++ b/packages/docusaurus-mdx-loader/src/deps.d.ts @@ -10,13 +10,13 @@ declare module '@mdx-js/mdx' { import type {Processor} from 'unified'; import type {RemarkOrRehypePlugin} from '@docusaurus/mdx-loader'; - export interface Options { + export type Options = { filepath?: string; skipExport?: boolean; wrapExport?: string; remarkPlugins?: RemarkOrRehypePlugin[]; rehypePlugins?: RemarkOrRehypePlugin[]; - } + }; export function sync(content: string, options?: Options): string; export function createMdxAstCompiler(options?: Options): Processor; diff --git a/packages/docusaurus-mdx-loader/src/index.ts b/packages/docusaurus-mdx-loader/src/index.ts index 8d6e55c79c5e..4991f774cf1e 100644 --- a/packages/docusaurus-mdx-loader/src/index.ts +++ b/packages/docusaurus-mdx-loader/src/index.ts @@ -182,9 +182,9 @@ export default async function mdxLoader( // Partial are not expected to have associated metadata files or front matter const isMDXPartial = options.isMDXPartial?.(filePath); if (isMDXPartial && hasFrontMatter) { - const errorMessage = `Docusaurus MDX partial files should not contain FrontMatter. + const errorMessage = `Docusaurus MDX partial files should not contain front matter. Those partial files use the _ prefix as a convention by default, but this is configurable. -File at ${filePath} contains FrontMatter that will be ignored: +File at ${filePath} contains front matter that will be ignored: ${JSON.stringify(frontMatter, null, 2)}`; if (!options.isMDXPartialFrontMatterWarningDisabled) { diff --git a/packages/docusaurus-mdx-loader/src/remark/headings/index.ts b/packages/docusaurus-mdx-loader/src/remark/headings/index.ts index c964b8d266c1..51b0cb6c7bbd 100644 --- a/packages/docusaurus-mdx-loader/src/remark/headings/index.ts +++ b/packages/docusaurus-mdx-loader/src/remark/headings/index.ts @@ -9,9 +9,8 @@ import {parseMarkdownHeadingId, createSlugger} from '@docusaurus/utils'; import visit from 'unist-util-visit'; -import toString from 'mdast-util-to-string'; +import mdastToString from 'mdast-util-to-string'; import type {Transformer} from 'unified'; -import type {Parent} from 'unist'; import type {Heading, Text} from 'mdast'; export default function plugin(): Transformer { @@ -30,10 +29,8 @@ export default function plugin(): Transformer { const headingTextNodes = headingNode.children.filter( ({type}) => !['html', 'jsx'].includes(type), ); - const heading = toString( - headingTextNodes.length > 0 - ? ({children: headingTextNodes} as Parent) - : headingNode, + const heading = mdastToString( + headingTextNodes.length > 0 ? headingTextNodes : headingNode, ); // Support explicit heading IDs diff --git a/packages/docusaurus-mdx-loader/src/remark/toc/index.ts b/packages/docusaurus-mdx-loader/src/remark/toc/index.ts index e733d5ab93a4..e10dbe70a3f3 100644 --- a/packages/docusaurus-mdx-loader/src/remark/toc/index.ts +++ b/packages/docusaurus-mdx-loader/src/remark/toc/index.ts @@ -27,9 +27,9 @@ const isImport = (child: Node): child is Literal => child.type === 'import'; const hasImports = (index: number) => index > -1; const isExport = (child: Node): child is Literal => child.type === 'export'; -interface PluginOptions { +type PluginOptions = { name?: string; -} +}; const isTarget = (child: Literal, name: string) => { let found = false; diff --git a/packages/docusaurus-migrate/src/types.ts b/packages/docusaurus-migrate/src/types.ts index 8a3583fcfad2..022139f3489d 100644 --- a/packages/docusaurus-migrate/src/types.ts +++ b/packages/docusaurus-migrate/src/types.ts @@ -37,7 +37,7 @@ export type SidebarEntries = { | Array<{[key: string]: unknown} | string>; }; -export interface VersionTwoConfig { +export type VersionTwoConfig = { baseUrl: string; favicon: string; tagline?: string; @@ -93,7 +93,7 @@ export interface VersionTwoConfig { [key: string]: unknown; } )[]; -} +}; export type VersionOneConfig = { title?: string; diff --git a/packages/docusaurus-module-type-aliases/src/index.d.ts b/packages/docusaurus-module-type-aliases/src/index.d.ts index 0e4b69c68759..9d98309ef69c 100644 --- a/packages/docusaurus-module-type-aliases/src/index.d.ts +++ b/packages/docusaurus-module-type-aliases/src/index.d.ts @@ -140,8 +140,9 @@ declare module '@docusaurus/Head' { declare module '@docusaurus/Link' { import type {CSSProperties, ComponentProps} from 'react'; + import type {NavLinkProps as RRNavLinkProps} from 'react-router-dom'; - type NavLinkProps = Partial; + type NavLinkProps = Partial; export type Props = NavLinkProps & ComponentProps<'a'> & { readonly className?: string; diff --git a/packages/docusaurus-plugin-content-blog/src/__tests__/frontMatter.test.ts b/packages/docusaurus-plugin-content-blog/src/__tests__/frontMatter.test.ts index 99e3c694bfbd..cb1020c680ef 100644 --- a/packages/docusaurus-plugin-content-blog/src/__tests__/frontMatter.test.ts +++ b/packages/docusaurus-plugin-content-blog/src/__tests__/frontMatter.test.ts @@ -314,7 +314,10 @@ describe('validateBlogPostFrontMatter tags', () => { {tags: ['hello', {label: 'tagLabel', permalink: '/tagPermalink'}]}, ], invalidFrontMatters: [ - [{tags: ''}, '"tags" does not look like a valid FrontMatter Yaml array.'], + [ + {tags: ''}, + '"tags" does not look like a valid front matter Yaml array.', + ], [{tags: ['']}, 'not allowed to be empty'], ], // See https://github.com/facebook/docusaurus/issues/4642 diff --git a/packages/docusaurus-plugin-content-blog/src/index.ts b/packages/docusaurus-plugin-content-blog/src/index.ts index c1b8d82089ef..3414d2820a07 100644 --- a/packages/docusaurus-plugin-content-blog/src/index.ts +++ b/packages/docusaurus-plugin-content-blog/src/index.ts @@ -102,7 +102,7 @@ export default async function pluginContentBlog( ) as string[]; }, - async getTranslationFiles() { + getTranslationFiles() { return getTranslationFiles(options); }, diff --git a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts index e7fd5a65ab88..1733bff9bc16 100644 --- a/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts +++ b/packages/docusaurus-plugin-content-blog/src/plugin-content-blog.d.ts @@ -10,7 +10,7 @@ declare module '@docusaurus/plugin-content-blog' { import type {FrontMatterTag, Tag} from '@docusaurus/utils'; import type {Overwrite} from 'utility-types'; - export interface Assets { + export type Assets = { /** * If `metadata.image` is a collocated image path, this entry will be the * bundler-generated image path. Otherwise, it's empty, and the image URL @@ -25,13 +25,9 @@ declare module '@docusaurus/plugin-content-blog' { * should be accessed through `authors.imageURL`. */ authorsImageUrls: (string | undefined)[]; - } + }; - /** - * Unknown keys are allowed, so that we can pass custom fields to authors, - * e.g., `twitter`. - */ - export interface Author extends Record { + export type Author = { /** * If `name` doesn't exist, an `imageURL` is expected. */ @@ -55,7 +51,12 @@ declare module '@docusaurus/plugin-content-blog' { * to generate a fallback `mailto:` URL. */ email?: string; - } + /** + * Unknown keys are allowed, so that we can pass custom fields to authors, + * e.g., `twitter`. + */ + [key: string]: unknown; + }; /** * Everything is partial/unnormalized, because front matter is always @@ -443,8 +444,6 @@ declare module '@theme/BlogPostPage' { >; export type Content = { - // TODO remove this. `metadata.frontMatter` is preferred because it can be - // accessed in enhanced plugins /** Same as `metadata.frontMatter` */ readonly frontMatter: FrontMatter; /** diff --git a/packages/docusaurus-plugin-content-blog/src/types.ts b/packages/docusaurus-plugin-content-blog/src/types.ts index a96390f71d51..220ddbf1d579 100644 --- a/packages/docusaurus-plugin-content-blog/src/types.ts +++ b/packages/docusaurus-plugin-content-blog/src/types.ts @@ -11,39 +11,41 @@ import type {Metadata as BlogPaginatedMetadata} from '@theme/BlogListPage'; export type BlogContentPaths = ContentPaths; -export interface BlogContent { +export type BlogContent = { blogSidebarTitle: string; blogPosts: BlogPost[]; blogListPaginated: BlogPaginated[]; blogTags: BlogTags; blogTagsListPath: string | null; -} +}; -export interface BlogTags { +export type BlogTags = { // TODO, the key is the tag slug/permalink // This is due to legacy frontmatter: tags: // [{label: "xyz", permalink: "/1"}, {label: "xyz", permalink: "/2"}] // Soon we should forbid declaring permalink through frontmatter [tagKey: string]: BlogTag; -} +}; -export interface BlogTag { +export type BlogTag = { name: string; - items: string[]; // blog post permalinks + /** Blog post permalinks. */ + items: string[]; permalink: string; pages: BlogPaginated[]; -} +}; -export interface BlogPost { +export type BlogPost = { id: string; metadata: BlogPostMetadata; content: string; -} +}; -export interface BlogPaginated { +export type BlogPaginated = { metadata: BlogPaginatedMetadata; - items: string[]; // blog post permalinks -} + /** Blog post permalinks. */ + items: string[]; +}; export type BlogBrokenMarkdownLink = BrokenMarkdownLink; export type BlogMarkdownLoaderOptions = { diff --git a/packages/docusaurus-plugin-content-docs/src/__tests__/frontMatter.test.ts b/packages/docusaurus-plugin-content-docs/src/__tests__/frontMatter.test.ts index 7e295afb0cb0..40f2f3f54fee 100644 --- a/packages/docusaurus-plugin-content-docs/src/__tests__/frontMatter.test.ts +++ b/packages/docusaurus-plugin-content-docs/src/__tests__/frontMatter.test.ts @@ -265,10 +265,13 @@ describe('validateDocFrontMatter tags', () => { validFrontMatters: [{}, {tags: undefined}, {tags: ['tag1', 'tag2']}], convertibleFrontMatter: [[{tags: ['tag1', 42]}, {tags: ['tag1', '42']}]], invalidFrontMatters: [ - [{tags: 42}, '"tags" does not look like a valid FrontMatter Yaml array.'], + [ + {tags: 42}, + '"tags" does not look like a valid front matter Yaml array.', + ], [ {tags: 'tag1, tag2'}, - '"tags" does not look like a valid FrontMatter Yaml array.', + '"tags" does not look like a valid front matter Yaml array.', ], [{tags: [{}]}, '"tags[0]" does not look like a valid tag'], [{tags: [true]}, '"tags[0]" does not look like a valid tag'], diff --git a/packages/docusaurus-plugin-content-docs/src/index.ts b/packages/docusaurus-plugin-content-docs/src/index.ts index ed35fa390c55..a0dc21768960 100644 --- a/packages/docusaurus-plugin-content-docs/src/index.ts +++ b/packages/docusaurus-plugin-content-docs/src/index.ts @@ -106,7 +106,7 @@ export default async function pluginContentDocs( }); }, - async getTranslationFiles({content}) { + getTranslationFiles({content}) { return getLoadedContentTranslationFiles(content); }, diff --git a/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts b/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts index 92d375fc700a..271bfa4923db 100644 --- a/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts +++ b/packages/docusaurus-plugin-content-docs/src/plugin-content-docs.d.ts @@ -10,9 +10,9 @@ declare module '@docusaurus/plugin-content-docs' { import type {ContentPaths, Tag, FrontMatterTag} from '@docusaurus/utils'; import type {Required} from 'utility-types'; - export interface Assets { + export type Assets = { image?: string; - } + }; /** * Custom callback for parsing number prefixes from file/folder names. diff --git a/packages/docusaurus-plugin-content-docs/src/sidebars/types.ts b/packages/docusaurus-plugin-content-docs/src/sidebars/types.ts index 9f4d68a3ae45..2dfaf5b7f553 100644 --- a/packages/docusaurus-plugin-content-docs/src/sidebars/types.ts +++ b/packages/docusaurus-plugin-content-docs/src/sidebars/types.ts @@ -254,18 +254,15 @@ export type SidebarItemsGenerator = ( generatorArgs: SidebarItemsGeneratorArgs, ) => Promise; -// Also inject the default generator to conveniently wrap/enhance/sort the -// default sidebar gen logic -// see https://github.com/facebook/docusaurus/issues/4640#issuecomment-822292320 -export type SidebarItemsGeneratorOptionArgs = { - /** - * Useful to re-use/enhance the default sidebar generation logic from - * Docusaurus. - */ - defaultSidebarItemsGenerator: SidebarItemsGenerator; -} & SidebarItemsGeneratorArgs; export type SidebarItemsGeneratorOption = ( - generatorArgs: SidebarItemsGeneratorOptionArgs, + generatorArgs: { + /** + * Useful to re-use/enhance the default sidebar generation logic from + * Docusaurus. + * @see https://github.com/facebook/docusaurus/issues/4640#issuecomment-822292320 + */ + defaultSidebarItemsGenerator: SidebarItemsGenerator; + } & SidebarItemsGeneratorArgs, ) => Promise; export type SidebarProcessorParams = { diff --git a/packages/docusaurus-plugin-ideal-image/src/deps.d.ts b/packages/docusaurus-plugin-ideal-image/src/deps.d.ts index 769d0561cc60..839a35fac984 100644 --- a/packages/docusaurus-plugin-ideal-image/src/deps.d.ts +++ b/packages/docusaurus-plugin-ideal-image/src/deps.d.ts @@ -33,12 +33,12 @@ declare module '@endiliey/react-ideal-image' { | 'noicon' | 'offline'; - export interface SrcType { + export type SrcType = { width: number; src?: string; size?: number; format?: 'webp' | 'jpeg' | 'png' | 'gif'; - } + }; type ThemeKey = 'placeholder' | 'img' | 'icon' | 'noscript'; diff --git a/packages/docusaurus-remark-plugin-npm2yarn/src/index.ts b/packages/docusaurus-remark-plugin-npm2yarn/src/index.ts index 19c03c4b21c5..0764763e9540 100644 --- a/packages/docusaurus-remark-plugin-npm2yarn/src/index.ts +++ b/packages/docusaurus-remark-plugin-npm2yarn/src/index.ts @@ -11,9 +11,9 @@ import type {Node, Parent} from 'unist'; import visit from 'unist-util-visit'; import npmToYarn from 'npm-to-yarn'; -interface PluginOptions { +type PluginOptions = { sync?: boolean; -} +}; // E.g. global install: 'npm i' -> 'yarn' const convertNpmToYarn = (npmCode: string) => npmToYarn(npmCode, 'yarn'); diff --git a/packages/docusaurus-theme-classic/src/index.ts b/packages/docusaurus-theme-classic/src/index.ts index 64f56392a45e..8aa1c7b805ad 100644 --- a/packages/docusaurus-theme-classic/src/index.ts +++ b/packages/docusaurus-theme-classic/src/index.ts @@ -118,7 +118,7 @@ export default function docusaurusThemeClassic( return '../src/theme'; }, - getTranslationFiles: async () => getTranslationFiles({themeConfig}), + getTranslationFiles: () => getTranslationFiles({themeConfig}), translateThemeConfig: (params) => translateThemeConfig({ diff --git a/packages/docusaurus-theme-common/src/contexts/docsSidebar.tsx b/packages/docusaurus-theme-common/src/contexts/docsSidebar.tsx index 2fb4d1cb0f19..56aacc9380ed 100644 --- a/packages/docusaurus-theme-common/src/contexts/docsSidebar.tsx +++ b/packages/docusaurus-theme-common/src/contexts/docsSidebar.tsx @@ -13,11 +13,11 @@ import {ReactContextError} from '../utils/reactUtils'; // Inspired by https://github.com/jamiebuilds/unstated-next/blob/master/src/unstated-next.tsx const EmptyContext: unique symbol = Symbol('EmptyContext'); -type SidebarContextValue = {name: string; items: PropSidebar}; +type ContextValue = {name: string; items: PropSidebar}; -const Context = React.createContext< - SidebarContextValue | null | typeof EmptyContext ->(EmptyContext); +const Context = React.createContext( + EmptyContext, +); /** * Provide the current sidebar to your children. @@ -31,7 +31,7 @@ export function DocsSidebarProvider({ name: string | undefined; items: PropSidebar | undefined; }): JSX.Element { - const stableValue: SidebarContextValue | null = useMemo( + const stableValue: ContextValue | null = useMemo( () => name && items ? { @@ -45,9 +45,9 @@ export function DocsSidebarProvider({ } /** - * Gets the sidebar data that's currently displayed, or `null` if there isn't one + * Gets the sidebar that's currently displayed, or `null` if there isn't one */ -export function useDocsSidebar(): SidebarContextValue | null { +export function useDocsSidebar(): ContextValue | null { const value = useContext(Context); if (value === EmptyContext) { throw new ReactContextError('DocsSidebarProvider'); diff --git a/packages/docusaurus-theme-common/src/utils/docsUtils.tsx b/packages/docusaurus-theme-common/src/utils/docsUtils.tsx index 64e700a48722..13e63bd44def 100644 --- a/packages/docusaurus-theme-common/src/utils/docsUtils.tsx +++ b/packages/docusaurus-theme-common/src/utils/docsUtils.tsx @@ -220,8 +220,9 @@ export function useDocsVersionCandidates( /** * The layout components, like navbar items, must be able to work on all pages, - * even on non-doc ones. This hook would always return a sidebar to be linked - * to. See also {@link useDocsVersionCandidates} for how this selection is done. + * even on non-doc ones where there's no version context, so a sidebar ID could + * be ambiguous. This hook would always return a sidebar to be linked to. See + * also {@link useDocsVersionCandidates} for how this selection is done. * * @throws This hook throws if a sidebar with said ID is not found. */ @@ -252,8 +253,9 @@ export function useLayoutDocsSidebar( /** * The layout components, like navbar items, must be able to work on all pages, - * even on non-doc ones. This hook would always return a doc to be linked - * to. See also {@link useDocsVersionCandidates} for how this selection is done. + * even on non-doc ones where there's no version context, so a doc ID could be + * ambiguous. This hook would always return a doc to be linked to. See also + * {@link useDocsVersionCandidates} for how this selection is done. * * @throws This hook throws if a doc with said ID is not found. */ diff --git a/packages/docusaurus-theme-common/src/utils/metadataUtils.tsx b/packages/docusaurus-theme-common/src/utils/metadataUtils.tsx index d7b85f0d04b3..9610faa2e40b 100644 --- a/packages/docusaurus-theme-common/src/utils/metadataUtils.tsx +++ b/packages/docusaurus-theme-common/src/utils/metadataUtils.tsx @@ -12,13 +12,13 @@ import useRouteContext from '@docusaurus/useRouteContext'; import {useBaseUrlUtils} from '@docusaurus/useBaseUrl'; import {useTitleFormatter} from './generalUtils'; -interface PageMetadataProps { +type PageMetadataProps = { readonly title?: string; readonly description?: string; readonly keywords?: readonly string[] | string; readonly image?: string; readonly children?: ReactNode; -} +}; /** * Helper component to manipulate page metadata and override site defaults. diff --git a/packages/docusaurus-theme-common/src/utils/storageUtils.ts b/packages/docusaurus-theme-common/src/utils/storageUtils.ts index d5dcbdc8c3f5..08ab3be1aee8 100644 --- a/packages/docusaurus-theme-common/src/utils/storageUtils.ts +++ b/packages/docusaurus-theme-common/src/utils/storageUtils.ts @@ -54,11 +54,11 @@ Possible reasons: running Docusaurus in an iframe, in an incognito browser sessi } // Convenient storage interface for a single storage key -export interface StorageSlot { +export type StorageSlot = { get: () => string | null; set: (value: string) => void; del: () => void; -} +}; const NoopStorageSlot: StorageSlot = { get: () => null, diff --git a/packages/docusaurus-theme-common/src/utils/tocUtils.ts b/packages/docusaurus-theme-common/src/utils/tocUtils.ts index c5a7fc9c6659..2b83f1a2f920 100644 --- a/packages/docusaurus-theme-common/src/utils/tocUtils.ts +++ b/packages/docusaurus-theme-common/src/utils/tocUtils.ts @@ -101,7 +101,7 @@ function filterTOC({ * to ensure that weird TOC structures preserve their semantics. For example, an * h3-h2-h4 sequence should not be treeified as an "h3 > h4" hierarchy with * min=3, max=4, but should rather be "[h3, h4]" (since the h2 heading has split - * the two headings and they are not parents) + * the two headings and they are not parent-children) */ export function useFilteredAndTreeifiedTOC({ toc, diff --git a/packages/docusaurus-theme-live-codeblock/src/deps.d.ts b/packages/docusaurus-theme-live-codeblock/src/deps.d.ts index 57918444adca..036cdb62f1b6 100644 --- a/packages/docusaurus-theme-live-codeblock/src/deps.d.ts +++ b/packages/docusaurus-theme-live-codeblock/src/deps.d.ts @@ -10,10 +10,10 @@ declare module '@philpl/buble' { // eslint-disable-next-line import/no-extraneous-dependencies, no-restricted-syntax export * from 'buble'; export const features: string[]; - export interface TransformOptions extends OriginalTransformOptions { + export type TransformOptions = OriginalTransformOptions & { transforms?: OriginalTransformOptions['transforms'] & { asyncAwait?: boolean; getterSetter?: boolean; }; - } + }; } diff --git a/packages/docusaurus-theme-live-codeblock/src/theme-live-codeblock.d.ts b/packages/docusaurus-theme-live-codeblock/src/theme-live-codeblock.d.ts index b377abadb66a..5bb5e51d2d26 100644 --- a/packages/docusaurus-theme-live-codeblock/src/theme-live-codeblock.d.ts +++ b/packages/docusaurus-theme-live-codeblock/src/theme-live-codeblock.d.ts @@ -23,9 +23,9 @@ declare module '@theme/Playground' { } declare module '@theme/ReactLiveScope' { - interface Scope { + type Scope = { [key: string]: unknown; - } + }; const ReactLiveScope: Scope; export default ReactLiveScope; diff --git a/packages/docusaurus-types/src/index.d.ts b/packages/docusaurus-types/src/index.d.ts index 58969aa81136..7bc1f119a2ee 100644 --- a/packages/docusaurus-types/src/index.d.ts +++ b/packages/docusaurus-types/src/index.d.ts @@ -86,7 +86,7 @@ export type DocusaurusConfig = { | string | { src: string; - [key: string]: unknown; + [key: string]: string | boolean | undefined; } )[]; clientModules: string[]; @@ -96,7 +96,7 @@ export type DocusaurusConfig = { | string | { href: string; - [key: string]: unknown; + [key: string]: string | boolean | undefined; } )[]; titleDelimiter?: string; @@ -304,16 +304,16 @@ export type ThemeConfigValidationContext = { export type Plugin = { name: string; - loadContent?: () => Promise; + loadContent?: () => Promise | Content; contentLoaded?: (args: { /** the content loaded by this plugin instance */ content: Content; // /** content loaded by ALL the plugins */ allContent: AllContent; actions: PluginContentLoadedActions; - }) => Promise; + }) => Promise | void; routesLoaded?: (routes: RouteConfig[]) => void; // TODO remove soon, deprecated (alpha-60) - postBuild?: (props: Props & {content: Content}) => Promise; + postBuild?: (props: Props & {content: Content}) => Promise | void; // TODO refactor the configureWebpack API surface: use an object instead of // multiple params (requires breaking change) configureWebpack?: ( @@ -342,8 +342,10 @@ export type Plugin = { // translations getTranslationFiles?: (args: { content: Content; - }) => Promise; - getDefaultCodeTranslationMessages?: () => Promise<{[id: string]: string}>; + }) => Promise | TranslationFile[]; + getDefaultCodeTranslationMessages?: () => + | Promise<{[id: string]: string}> + | {[id: string]: string}; translateContent?: (args: { /** The content loaded by this plugin instance. */ content: Content; diff --git a/packages/docusaurus-utils-validation/src/validationSchemas.ts b/packages/docusaurus-utils-validation/src/validationSchemas.ts index f49b962a853b..4e6134a7b2a1 100644 --- a/packages/docusaurus-utils-validation/src/validationSchemas.ts +++ b/packages/docusaurus-utils-validation/src/validationSchemas.ts @@ -83,7 +83,7 @@ export const FrontMatterTagsSchema = JoiFrontMatter.array() .items(FrontMatterTagSchema) .messages({ 'array.base': - '{{#label}} does not look like a valid FrontMatter Yaml array.', + '{{#label}} does not look like a valid front matter Yaml array.', }); export const FrontMatterTOCHeadingLevels = { diff --git a/packages/docusaurus/src/client/PendingNavigation.tsx b/packages/docusaurus/src/client/PendingNavigation.tsx index 56e7e9c062b5..d9a87706a1fa 100644 --- a/packages/docusaurus/src/client/PendingNavigation.tsx +++ b/packages/docusaurus/src/client/PendingNavigation.tsx @@ -19,18 +19,18 @@ import './nprogress.css'; nprogress.configure({showSpinner: false}); -interface Props extends RouteComponentProps { +type Props = RouteComponentProps & { readonly routes: RouteConfig[]; readonly delay: number; readonly location: Location; -} -interface State { +}; +type State = { nextRouteHasLoaded: boolean; -} +}; class PendingNavigation extends React.Component { - previousLocation: Location | null; - progressBarTimeout: NodeJS.Timeout | null; + private previousLocation: Location | null; + private progressBarTimeout: NodeJS.Timeout | null; constructor(props: Props) { super(props); diff --git a/packages/docusaurus/src/client/exports/ErrorBoundary.tsx b/packages/docusaurus/src/client/exports/ErrorBoundary.tsx index 9b9515898a84..5fc50be15dbd 100644 --- a/packages/docusaurus/src/client/exports/ErrorBoundary.tsx +++ b/packages/docusaurus/src/client/exports/ErrorBoundary.tsx @@ -11,9 +11,9 @@ import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment'; import type {Props} from '@docusaurus/ErrorBoundary'; import DefaultFallback from '@theme/Error'; -interface State { +type State = { error: Error | null; -} +}; export default class ErrorBoundary extends React.Component { constructor(props: Props) { diff --git a/packages/docusaurus/src/deps.d.ts b/packages/docusaurus/src/deps.d.ts index f977549c7c7a..acaccfcebb0c 100644 --- a/packages/docusaurus/src/deps.d.ts +++ b/packages/docusaurus/src/deps.d.ts @@ -26,9 +26,9 @@ declare module 'react-loadable-ssr-addon-v5-slorber' { modulesToBeLoaded: string[], ): {js: Asset[]; css: Asset[]}; - interface ReactLoadableSSRAddon { + type ReactLoadableSSRAddon = { new (props: {filename: string}); - } + }; const plugin: ReactLoadableSSRAddon; export default plugin; @@ -47,7 +47,7 @@ declare module '@slorber/static-site-generator-webpack-plugin' { noIndex: boolean; }; - interface StaticSiteGeneratorPlugin { + type StaticSiteGeneratorPlugin = { new (props: { entry: string; locals: Locals; @@ -55,7 +55,7 @@ declare module '@slorber/static-site-generator-webpack-plugin' { preferFoldersOutput?: boolean; globals: {[key: string]: unknown}; }); - } + }; const plugin: StaticSiteGeneratorPlugin; export default plugin; diff --git a/packages/docusaurus/src/server/plugins/synthetic.ts b/packages/docusaurus/src/server/plugins/synthetic.ts index f44fad1eb3d8..67e297ffe5f5 100644 --- a/packages/docusaurus/src/server/plugins/synthetic.ts +++ b/packages/docusaurus/src/server/plugins/synthetic.ts @@ -36,26 +36,27 @@ export function createBootstrapPlugin({ return siteConfigClientModules; }, injectHtmlTags: () => { - const stylesheetsTags = stylesheets.map((source) => - typeof source === 'string' - ? `` - : ({ - tagName: 'link', - attributes: { - rel: 'stylesheet', - ...source, + const stylesheetsTags = stylesheets.map( + (source): string | HtmlTagObject => + typeof source === 'string' + ? `` + : { + tagName: 'link', + attributes: { + rel: 'stylesheet', + ...source, + }, }, - } as HtmlTagObject), ); - const scriptsTags = scripts.map((source) => + const scriptsTags = scripts.map((source): string | HtmlTagObject => typeof source === 'string' ? `` - : ({ + : { tagName: 'script', attributes: { ...source, }, - } as HtmlTagObject), + }, ); return { headTags: [...stylesheetsTags, ...scriptsTags], diff --git a/packages/docusaurus/src/webpack/plugins/CleanWebpackPlugin.ts b/packages/docusaurus/src/webpack/plugins/CleanWebpackPlugin.ts index e6bae7173dea..46b4ca424fde 100644 --- a/packages/docusaurus/src/webpack/plugins/CleanWebpackPlugin.ts +++ b/packages/docusaurus/src/webpack/plugins/CleanWebpackPlugin.ts @@ -33,7 +33,7 @@ import type {Compiler, Stats} from 'webpack'; import path from 'path'; import {sync as delSync} from 'del'; -export interface Options { +export type Options = { /** * Write Logs to Console * (Always enabled when dry is true) @@ -65,7 +65,7 @@ export interface Options { * default: ['**\/*'] */ cleanOnceBeforeBuildPatterns?: string[]; -} +}; export default class CleanWebpackPlugin { private readonly verbose: boolean; diff --git a/packages/docusaurus/src/webpack/plugins/WaitPlugin.ts b/packages/docusaurus/src/webpack/plugins/WaitPlugin.ts index ab2130911647..2ace27913e4c 100644 --- a/packages/docusaurus/src/webpack/plugins/WaitPlugin.ts +++ b/packages/docusaurus/src/webpack/plugins/WaitPlugin.ts @@ -10,9 +10,9 @@ import fs from 'fs-extra'; import waitOn from 'wait-on'; import type {Compiler} from 'webpack'; -interface WaitPluginOptions { +type WaitPluginOptions = { filepath: string; -} +}; export default class WaitPlugin { filepath: string; diff --git a/website/docs/api/plugin-methods/README.md b/website/docs/api/plugin-methods/README.md index 0e9d816c6f6d..a59fc2059f47 100644 --- a/website/docs/api/plugin-methods/README.md +++ b/website/docs/api/plugin-methods/README.md @@ -24,13 +24,13 @@ The plugin module's default export is a constructor function with the signature `context` is plugin-agnostic, and the same object will be passed into all plugins used for a Docusaurus website. The `context` object contains the following fields: ```ts -interface LoadContext { +type LoadContext = { siteDir: string; generatedFilesDir: string; siteConfig: DocusaurusConfig; outDir: string; baseUrl: string; -} +}; ``` ### `options` {#options} diff --git a/website/docs/api/plugin-methods/lifecycle-apis.md b/website/docs/api/plugin-methods/lifecycle-apis.md index e963f401251e..bc583e8d38e0 100644 --- a/website/docs/api/plugin-methods/lifecycle-apis.md +++ b/website/docs/api/plugin-methods/lifecycle-apis.md @@ -43,17 +43,17 @@ The data that was loaded in `loadContent` will be consumed in `contentLoaded`. I Create a route to add to the website. ```ts -interface RouteConfig { +type RouteConfig = { path: string; component: string; modules?: RouteModules; routes?: RouteConfig[]; exact?: boolean; priority?: number; -} -interface RouteModules { +}; +type RouteModules = { [module: string]: Module | RouteModules | RouteModules[]; -} +}; type Module = | { path: string; @@ -339,7 +339,7 @@ function injectHtmlTags(): { type HtmlTags = string | HtmlTagObject | (string | HtmlTagObject)[]; -interface HtmlTagObject { +type HtmlTagObject = { /** * Attributes of the HTML tag * E.g. `{'disabled': true, 'value': 'demo', 'rel': 'preconnect'}` @@ -355,7 +355,7 @@ interface HtmlTagObject { * The inner HTML */ innerHTML?: string; -} +}; ``` Example: diff --git a/website/docs/docusaurus-core.md b/website/docs/docusaurus-core.md index fcd35040dd0d..26316d033364 100644 --- a/website/docs/docusaurus-core.md +++ b/website/docs/docusaurus-core.md @@ -341,31 +341,31 @@ type PluginVersionInformation = | {readonly type: 'local'} | {readonly type: 'synthetic'}; -interface SiteMetadata { +type SiteMetadata = { readonly docusaurusVersion: string; readonly siteVersion?: string; readonly pluginVersions: Record; -} +}; -interface I18nLocaleConfig { +type I18nLocaleConfig = { label: string; direction: string; -} +}; -interface I18n { +type I18n = { defaultLocale: string; locales: [string, ...string[]]; currentLocale: string; localeConfigs: Record; -} +}; -interface DocusaurusContext { +type DocusaurusContext = { siteConfig: DocusaurusConfig; siteMetadata: SiteMetadata; globalData: Record; i18n: I18n; codeTranslations: Record; -} +}; ``` Usage example: diff --git a/website/src/components/Svg/index.tsx b/website/src/components/Svg/index.tsx index 3fe951af3571..a37a4eddd7ed 100644 --- a/website/src/components/Svg/index.tsx +++ b/website/src/components/Svg/index.tsx @@ -9,14 +9,14 @@ import React, {type ReactNode, type ComponentProps} from 'react'; import clsx from 'clsx'; import styles from './styles.module.css'; -export interface SvgIconProps extends ComponentProps<'svg'> { +export type SvgIconProps = ComponentProps<'svg'> & { viewBox?: string; size?: 'inherit' | 'small' | 'medium' | 'large'; color?: 'inherit' | 'primary' | 'secondary' | 'success' | 'error' | 'warning'; svgClass?: string; // Class attribute on the child colorAttr?: string; // Applies a color attribute to the SVG element. children: ReactNode; // Node passed into the SVG element. -} +}; export default function Svg(props: SvgIconProps): JSX.Element { const { diff --git a/website/src/components/TeamProfileCards/index.tsx b/website/src/components/TeamProfileCards/index.tsx index 7c212fe38b39..92b6858df745 100644 --- a/website/src/components/TeamProfileCards/index.tsx +++ b/website/src/components/TeamProfileCards/index.tsx @@ -19,13 +19,13 @@ function WebsiteLink({to, children}: {to: string; children?: ReactNode}) { ); } -interface ProfileProps { +type ProfileProps = { className?: string; name: string; children: ReactNode; githubUrl?: string; twitterUrl?: string; -} +}; function TeamProfileCard({ className, diff --git a/website/src/data/tweets.tsx b/website/src/data/tweets.tsx index 9656e1a5747b..157bc0fb0e67 100644 --- a/website/src/data/tweets.tsx +++ b/website/src/data/tweets.tsx @@ -9,9 +9,9 @@ import React from 'react'; import type {Props as Tweet} from '../components/Tweet'; -export interface TweetItem extends Tweet { +export type TweetItem = Tweet & { showOnHomepage: boolean; -} +}; const TWEETS: TweetItem[] = [ {