From 8d34bc8e44e8b0c23858074fada184df71c62bba Mon Sep 17 00:00:00 2001 From: yifancong Date: Wed, 6 Dec 2023 11:04:48 +0800 Subject: [PATCH] fix: some overall page types (#44) fix: some overall page types --- .changeset/three-bulldogs-drive.md | 5 ++++ .../src/components/Alert/change.tsx | 4 --- packages/components/src/utils/file.tsx | 29 ++++++++++--------- packages/components/src/utils/request.ts | 5 ++-- 4 files changed, 22 insertions(+), 21 deletions(-) create mode 100644 .changeset/three-bulldogs-drive.md diff --git a/.changeset/three-bulldogs-drive.md b/.changeset/three-bulldogs-drive.md new file mode 100644 index 00000000..aed80547 --- /dev/null +++ b/.changeset/three-bulldogs-drive.md @@ -0,0 +1,5 @@ +--- +'@rsdoctor/components': patch +--- + +fix(components): some components types. diff --git a/packages/components/src/components/Alert/change.tsx b/packages/components/src/components/Alert/change.tsx index 5db3cd11..4418d801 100644 --- a/packages/components/src/components/Alert/change.tsx +++ b/packages/components/src/components/Alert/change.tsx @@ -25,10 +25,6 @@ export const CodeChangeDrawerContent: React.FC { - if (process.env.NODE_ENV !== 'development') { - // TODO implement open codebase mr. - return null; - } return ( React.ReactNode); +}> & { __BASENAME__?: any; __RESOURCEPATH__?: any; children?: DataNode[] }; export const rootDirname = (file: string, sep = '/'): string | null => { const idx = file?.indexOf(sep); @@ -42,7 +46,7 @@ export function flattenDirectory( n: DataNode, parent: DataNode, sep = '/', - inlinedResourcePathKey: string, + inlinedResourcePathKey: keyof DataNode, dirTitle = (_dir: DataNode, defaultTitle: string): JSX.Element | string => defaultTitle, ) { if (n.isLeaf) return; @@ -55,7 +59,7 @@ export function flattenDirectory( parent.title = dirTitle(parent, defaultTitle); n.children && - n.children.forEach((c: any) => { + n.children.forEach((c) => { flattenDirectory(c, parent, sep, inlinedResourcePathKey, dirTitle); }); } else { @@ -63,7 +67,7 @@ export function flattenDirectory( n.title = dirTitle(n, n[basenameKey]); n.children && - n.children.forEach((c: any) => { + n.children.forEach((c) => { flattenDirectory(c, n, sep, inlinedResourcePathKey, dirTitle); }); } @@ -79,7 +83,7 @@ export function createFileStructures({ files: string[]; cwd?: string; sep?: string; - inlinedResourcePathKey?: string; + inlinedResourcePathKey?: keyof DataNode; dirTitle?(dir: DataNode, defaultTitle: string): JSX.Element | string; fileTitle?(file: string, basename: string): JSX.Element | string; }): DataNode[] { @@ -93,8 +97,7 @@ export function createFileStructures({ while (dir) { // find the match directory. - // eslint-disable-next-line no-loop-func - let exist = parent.children!.find((e: { title: string | null; }) => e.title === dir); + let exist = parent.children!.find((e) => e.title === dir) as DataNode; if (!exist) { const p = [parent[inlinedResourcePathKey], dir].filter(Boolean).join(sep); exist = { @@ -114,7 +117,7 @@ export function createFileStructures({ } // uniq - if (parent.children!.some((e: any) => get(e, inlinedResourcePathKey) === file)) return t; + if (parent.children!.some((e) => get(e, inlinedResourcePathKey) === file)) return t; parent.children!.push({ title() { @@ -125,21 +128,19 @@ export function createFileStructures({ isLeaf: true, [inlinedResourcePathKey]: file, [basenameKey]: basename, - } as any); + }); return t; }, { key: '0', children: [] }, ).children!; - res.forEach((e: { children: any[]; }) => { + res.forEach((e) => { e.children && - e.children.forEach((item: any) => { - flattenDirectory(item, e, sep, inlinedResourcePathKey, dirTitle); - }); + e.children.forEach((item) => flattenDirectory(item, e, sep, inlinedResourcePathKey, dirTitle)); }); - return res as DataNode[]; + return res; } export function beautifyPath(path: string, cwd: string) { diff --git a/packages/components/src/utils/request.ts b/packages/components/src/utils/request.ts index e44a7fdf..b4a1d7d9 100644 --- a/packages/components/src/utils/request.ts +++ b/packages/components/src/utils/request.ts @@ -65,10 +65,9 @@ const manifestUrlForDev = '/manifest.json'; export function getManifestUrl(): string { let file: string | void; - if (window[Manifest.DoctorManifestClientConstant.WindowPropertyForManifestUrl as any]) { + if ((window as { [key: string]: any })[Manifest.DoctorManifestClientConstant.WindowPropertyForManifestUrl]) { // load from window property - // @ts-ignore - file = window[Manifest.DoctorManifestClientConstant.WindowPropertyForManifestUrl]; // TODO: types + file = (window as { [key: string]: any })[Manifest.DoctorManifestClientConstant.WindowPropertyForManifestUrl]; } else { // load from url query file = getManifestUrlFromUrlQuery();