fix: handle type errors

This commit is contained in:
EnixCoda 2022-06-28 17:03:20 +08:00
parent 05507abbcb
commit c1f8456e7f

View file

@ -7,8 +7,8 @@ import { CopyFileButton, copyFileButtonClassName } from './CopyFileButton'
export function resolveMeta(): Partial<MetaData> {
const metaData = {
userName: $('[itemprop="author"] > a[rel="author"]', e => e.textContent?.trim()),
repoName: $('[itemprop="name"] > a[href]', e => e.textContent?.trim()),
userName: $('[itemprop="author"] > a[rel="author"]', e => e.textContent?.trim()) || undefined,
repoName: $('[itemprop="name"] > a[href]', e => e.textContent?.trim()) || undefined,
branchName: getCurrentBranch(true),
}
if (!metaData.userName || !metaData.repoName) {
@ -56,7 +56,7 @@ export function getCurrentBranch(passive = false) {
const findFileButtonSelector =
'#js-repo-pjax-container .repository-content .file-navigation a[data-hotkey="t"]'
const urlFromFindFileButton: string | undefined = $(
const urlFromFindFileButton: string | null = $(
findFileButtonSelector,
element => (element as HTMLAnchorElement).href,
)