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:
Joshua Chen 2022-03-06 13:09:10 +08:00 committed by GitHub
parent 9f925a42bf
commit 4db0c620de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
71 changed files with 210 additions and 174 deletions

View file

@ -363,7 +363,7 @@ export function getMainDocId({
doc.unversionedId === firstDocIdOfFirstSidebar,
)!;
}
return docs[0];
return docs[0]!;
}
return getMainDoc().unversionedId;

View file

@ -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(
', ',

View file

@ -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]!),
};
}

View file

@ -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),
};

View file

@ -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(