refactor: improve types in the frontend, misc fixes (#39142)

This commit is contained in:
silverwind
2026-08-31 04:12:25 -07:00
committed by GitHub
parent 535fc29ae8
commit 7c93ead628
46 changed files with 392 additions and 217 deletions
+9 -5
View File
@@ -21,7 +21,7 @@ export function extname(path: string): string {
}
/** test whether a variable is an object */
export function isObject<T = Record<string, any>>(obj: any): obj is T {
export function isObject(obj: unknown): obj is Record<string, unknown> {
return Object.prototype.toString.call(obj) === '[object Object]';
}
@@ -49,17 +49,21 @@ export function stripTags(text: string): string {
return text;
}
export function parseIssueHref(href: string): IssuePathInfo {
export function parseIssueHref(href: string): IssuePathInfo | null {
// FIXME: it should use pathname and trim the appSubUrl ahead
const path = (href || '').replace(/[#?].*$/, '');
const [_, ownerName, repoName, pathType, indexString] = /([^/]+)\/([^/]+)\/(issues|pulls)\/([0-9]+)/.exec(path) || [];
const match = /([^/]+)\/([^/]+)\/(issues|pulls)\/([0-9]+)/.exec(path);
if (!match) return null;
const [, ownerName, repoName, pathType, indexString] = match;
return {ownerName, repoName, pathType, indexString};
}
export function parseRepoOwnerPathInfo(pathname: string): RepoOwnerPathInfo {
export function parseRepoOwnerPathInfo(pathname: string): RepoOwnerPathInfo | null {
const appSubUrl = window.config.appSubUrl;
if (appSubUrl && pathname.startsWith(appSubUrl)) pathname = pathname.substring(appSubUrl.length);
const [_, ownerName, repoName] = /([^/]+)\/([^/]+)/.exec(pathname) || [];
const match = /([^/]+)\/([^/]+)/.exec(pathname);
if (!match) return null;
const [, ownerName, repoName] = match;
return {ownerName, repoName};
}