mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 23:57:22 +02:00
refactor: enable a few TS flags (#6852)
* refactor: enable a few TS flags * refactor * revert to working version * fix * better * change
This commit is contained in:
parent
9f925a42bf
commit
4db0c620de
71 changed files with 210 additions and 174 deletions
|
@ -363,7 +363,7 @@ export function getMainDocId({
|
|||
doc.unversionedId === firstDocIdOfFirstSidebar,
|
||||
)!;
|
||||
}
|
||||
return docs[0];
|
||||
return docs[0]!;
|
||||
}
|
||||
|
||||
return getMainDoc().unversionedId;
|
||||
|
|
|
@ -49,7 +49,7 @@ async function readCategoriesMetadata(contentPath: string) {
|
|||
const categoryToFile = _.groupBy(categoryFiles, path.dirname);
|
||||
return combinePromises(
|
||||
_.mapValues(categoryToFile, async (files, folder) => {
|
||||
const [filePath] = files;
|
||||
const filePath = files[0]!;
|
||||
if (files.length > 1) {
|
||||
logger.warn`There are more than one category metadata files for path=${folder}: ${files.join(
|
||||
', ',
|
||||
|
|
|
@ -201,12 +201,12 @@ export function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils {
|
|||
if (!sidebarName) {
|
||||
return emptySidebarNavigation();
|
||||
}
|
||||
if (!sidebarNameToNavigationItems[sidebarName]) {
|
||||
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
||||
if (!navigationItems) {
|
||||
throw new Error(
|
||||
`Doc with ID ${docId} wants to display sidebar ${sidebarName} but a sidebar with this name doesn't exist`,
|
||||
);
|
||||
}
|
||||
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
||||
const currentItemIndex = navigationItems.findIndex((item) => {
|
||||
if (item.type === 'doc') {
|
||||
return item.id === docId;
|
||||
|
@ -263,7 +263,7 @@ export function createSidebarsUtils(sidebars: Sidebars): SidebarsUtils {
|
|||
if (!sidebarName) {
|
||||
return emptySidebarNavigation();
|
||||
}
|
||||
const navigationItems = sidebarNameToNavigationItems[sidebarName];
|
||||
const navigationItems = sidebarNameToNavigationItems[sidebarName]!;
|
||||
const currentItemIndex = navigationItems.findIndex(
|
||||
isCurrentCategoryGeneratedIndexItem,
|
||||
);
|
||||
|
@ -341,7 +341,7 @@ Available document ids are:
|
|||
getCategoryGeneratedIndexList,
|
||||
getCategoryGeneratedIndexNavigation,
|
||||
checkSidebarsDocIds,
|
||||
getFirstLink: (id) => getFirstLink(sidebars[id]),
|
||||
getFirstLink: (id) => getFirstLink(sidebars[id]!),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -274,10 +274,14 @@ function translateVersion(
|
|||
translationFiles: Record<string, TranslationFile>,
|
||||
): LoadedVersion {
|
||||
const versionTranslations =
|
||||
translationFiles[getVersionFileName(version.versionName)].content;
|
||||
translationFiles[getVersionFileName(version.versionName)]?.content;
|
||||
if (!versionTranslations) {
|
||||
return version;
|
||||
}
|
||||
return {
|
||||
...version,
|
||||
versionLabel: versionTranslations['version.label']?.message,
|
||||
versionLabel:
|
||||
versionTranslations['version.label']?.message ?? version.versionLabel,
|
||||
sidebars: translateSidebars(version, versionTranslations),
|
||||
// docs: translateDocs(version.docs, versionTranslations),
|
||||
};
|
||||
|
|
|
@ -464,11 +464,11 @@ Please set the docs "sidebarPath" field in your config file to:
|
|||
// "last version" is not a very good concept nor api surface
|
||||
function getDefaultLastVersionName(versionNames: string[]) {
|
||||
if (versionNames.length === 1) {
|
||||
return versionNames[0];
|
||||
return versionNames[0]!;
|
||||
}
|
||||
return versionNames.filter(
|
||||
(versionName) => versionName !== CURRENT_VERSION_NAME,
|
||||
)[0];
|
||||
)[0]!;
|
||||
}
|
||||
|
||||
function checkVersionsOptions(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue