refactor: properly type docs version (#5284)

* Type docs version

Signed-off-by: Josh-Cena <sidachen2003@gmail.com>

* Move non-null assertions

Signed-off-by: Josh-Cena <sidachen2003@gmail.com>

* Test again
This commit is contained in:
Joshua Chen 2021-08-05 16:52:35 +08:00 committed by GitHub
parent bc6c67720a
commit 0a668366c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 66 additions and 29 deletions

View file

@ -15,7 +15,7 @@ import React, {
import {useThemeConfig, DocsVersionPersistence} from '../useThemeConfig';
import {isDocsPluginEnabled} from '../docsUtils';
import {useAllDocsData} from '@theme/hooks/useDocs';
import {useAllDocsData, GlobalPluginData} from '@theme/hooks/useDocs';
import DocsPreferredVersionStorage from './DocsPreferredVersionStorage';
@ -54,7 +54,7 @@ function readStorageState({
}: {
pluginIds: string[];
versionPersistence: DocsVersionPersistence;
allDocsData: any; // TODO find a way to type it :(
allDocsData: Record<string, GlobalPluginData>;
}): DocsPreferredVersionState {
// The storage value we read might be stale,
// and belong to a version that does not exist in the site anymore
@ -68,7 +68,7 @@ function readStorageState({
);
const pluginData = allDocsData[pluginId];
const versionExists = pluginData.versions.some(
(version: any) => version.name === preferredVersionNameUnsafe,
(version) => version.name === preferredVersionNameUnsafe,
);
if (versionExists) {
return {preferredVersionName: preferredVersionNameUnsafe};