chore: upgrade to TS 4.7, compile with NodeNext (#7586)

Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
This commit is contained in:
Joshua Chen 2022-06-16 01:15:11 +08:00 committed by GitHub
parent b503523f66
commit b4d93b9bd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
62 changed files with 225 additions and 195 deletions

View file

@ -18,15 +18,60 @@ import {
getActiveDocContext,
getDocVersionSuggestions,
} from './docsClientUtils';
import type {
GlobalPluginData,
GlobalVersion,
ActivePlugin,
ActiveDocContext,
DocVersionSuggestions,
} from '@docusaurus/plugin-content-docs/client';
import type {UseDataOptions} from '@docusaurus/types';
export type ActivePlugin = {
pluginId: string;
pluginData: GlobalPluginData;
};
export type ActiveDocContext = {
activeVersion?: GlobalVersion;
activeDoc?: GlobalDoc;
alternateDocVersions: {[versionName: string]: GlobalDoc};
};
export type GlobalDoc = {
/**
* For generated index pages, this is the `slug`, **not** `permalink`
* (without base URL). Because slugs have leading slashes but IDs don't,
* there won't be clashes.
*/
id: string;
path: string;
sidebar: string | undefined;
};
export type GlobalVersion = {
name: string;
label: string;
isLast: boolean;
path: string;
/** The doc with `slug: /`, or first doc in first sidebar */
mainDocId: string;
docs: GlobalDoc[];
/** Unversioned IDs. In development, this list is empty. */
draftIds: string[];
sidebars?: {[sidebarId: string]: GlobalSidebar};
};
export type GlobalSidebar = {
link?: {
label: string;
path: string;
};
// ... we may add other things here later
};
export type GlobalPluginData = {
path: string;
versions: GlobalVersion[];
breadcrumbs: boolean;
};
export type DocVersionSuggestions = {
/** Suggest the latest version */
latestVersionSuggestion: GlobalVersion;
/** Suggest the same doc, in latest version (if one exists) */
latestDocSuggestion?: GlobalDoc;
};
// Important to use a constant object to avoid React useEffect executions etc.
// see https://github.com/facebook/docusaurus/issues/5089
const StableEmptyObject = {};
@ -71,6 +116,7 @@ export function useActivePluginAndVersion(
};
}
/** Versions are returned ordered (most recent first). */
export function useVersions(pluginId: string | undefined): GlobalVersion[] {
const data = useDocsData(pluginId);
return data.versions;
@ -81,6 +127,10 @@ export function useLatestVersion(pluginId: string | undefined): GlobalVersion {
return getLatestVersion(data);
}
/**
* Returns `undefined` on doc-unrelated pages, because there's no version
* currently considered as active.
*/
export function useActiveVersion(
pluginId: string | undefined,
): GlobalVersion | undefined {
@ -96,7 +146,9 @@ export function useActiveDocContext(
const {pathname} = useLocation();
return getActiveDocContext(data, pathname);
}
/**
* Useful to say "hey, you are not on the latest docs version, please switch"
*/
export function useDocVersionSuggestions(
pluginId: string | undefined,
): DocVersionSuggestions {

View file

@ -616,89 +616,3 @@ declare module '@theme/DocPage' {
export default function DocPage(props: Props): JSX.Element;
}
// TODO TS only supports reading `exports` in 4.7. We will need to merge the
// type defs (and JSDoc) here with the implementation after that
declare module '@docusaurus/plugin-content-docs/client' {
import type {UseDataOptions} from '@docusaurus/types';
export type ActivePlugin = {
pluginId: string;
pluginData: GlobalPluginData;
};
export type ActiveDocContext = {
activeVersion?: GlobalVersion;
activeDoc?: GlobalDoc;
alternateDocVersions: {[versionName: string]: GlobalDoc};
};
export type GlobalDoc = {
/**
* For generated index pages, this is the `slug`, **not** `permalink`
* (without base URL). Because slugs have leading slashes but IDs don't,
* there won't be clashes.
*/
id: string;
path: string;
sidebar: string | undefined;
};
export type GlobalVersion = {
name: string;
label: string;
isLast: boolean;
path: string;
/** The doc with `slug: /`, or first doc in first sidebar */
mainDocId: string;
docs: GlobalDoc[];
/** Unversioned IDs. In development, this list is empty. */
draftIds: string[];
sidebars?: {[sidebarId: string]: GlobalSidebar};
};
export type GlobalSidebar = {
link?: {
label: string;
path: string;
};
// ... we may add other things here later
};
export type GlobalPluginData = {
path: string;
versions: GlobalVersion[];
breadcrumbs: boolean;
};
export type DocVersionSuggestions = {
/** Suggest the latest version */
latestVersionSuggestion: GlobalVersion;
/** Suggest the same doc, in latest version (if one exists) */
latestDocSuggestion?: GlobalDoc;
};
export const useAllDocsData: () => {[pluginId: string]: GlobalPluginData};
export const useDocsData: (pluginId?: string) => GlobalPluginData;
export const useActivePlugin: (
options?: UseDataOptions,
) => ActivePlugin | undefined;
export const useActivePluginAndVersion: (
options?: UseDataOptions,
) =>
| {activePlugin: ActivePlugin; activeVersion: GlobalVersion | undefined}
| undefined;
/** Versions are returned ordered (most recent first). */
export const useVersions: (pluginId?: string) => GlobalVersion[];
export const useLatestVersion: (pluginId?: string) => GlobalVersion;
/**
* Returns `undefined` on doc-unrelated pages, because there's no version
* currently considered as active.
*/
export const useActiveVersion: (
pluginId?: string,
) => GlobalVersion | undefined;
export const useActiveDocContext: (pluginId?: string) => ActiveDocContext;
/**
* Useful to say "hey, you are not on the latest docs version, please switch"
*/
export const useDocVersionSuggestions: (
pluginId?: string,
) => DocVersionSuggestions;
}