mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 23:57:22 +02:00
refactor: reduce number of leaked anys (#7465)
This commit is contained in:
parent
6e62bba30f
commit
89b0fff128
39 changed files with 121 additions and 89 deletions
|
@ -92,8 +92,12 @@ async function readMetadataPath(metadataPath: string) {
|
|||
*
|
||||
* `{image: "./myImage.png"}` => `{image: require("./myImage.png")}`
|
||||
*/
|
||||
function createAssetsExportCode(assets: {[key: string]: unknown}) {
|
||||
if (Object.keys(assets).length === 0) {
|
||||
function createAssetsExportCode(assets: unknown) {
|
||||
if (
|
||||
typeof assets !== 'object' ||
|
||||
!assets ||
|
||||
Object.keys(assets).length === 0
|
||||
) {
|
||||
return 'undefined';
|
||||
}
|
||||
|
||||
|
@ -101,7 +105,7 @@ function createAssetsExportCode(assets: {[key: string]: unknown}) {
|
|||
function createAssetValueCode(assetValue: unknown): string | undefined {
|
||||
if (Array.isArray(assetValue)) {
|
||||
const arrayItemCodes = assetValue.map(
|
||||
(item) => createAssetValueCode(item) ?? 'undefined',
|
||||
(item: unknown) => createAssetValueCode(item) ?? 'undefined',
|
||||
);
|
||||
return `[${arrayItemCodes.join(', ')}]`;
|
||||
}
|
||||
|
@ -119,7 +123,7 @@ function createAssetsExportCode(assets: {[key: string]: unknown}) {
|
|||
const assetEntries = Object.entries(assets);
|
||||
|
||||
const codeLines = assetEntries
|
||||
.map(([key, value]) => {
|
||||
.map(([key, value]: [string, unknown]) => {
|
||||
const assetRequireCode = createAssetValueCode(value);
|
||||
return assetRequireCode ? `"${key}": ${assetRequireCode},` : undefined;
|
||||
})
|
||||
|
@ -227,7 +231,7 @@ ${JSON.stringify(frontMatter, null, 2)}`;
|
|||
: undefined;
|
||||
|
||||
const metadata = metadataJsonString
|
||||
? JSON.parse(metadataJsonString)
|
||||
? (JSON.parse(metadataJsonString) as {[key: string]: unknown})
|
||||
: undefined;
|
||||
|
||||
const assets =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue