chore: enable noUncheckedIndexedAccess, better type check (#2608)

This commit is contained in:
Stephen Zhou
2025-01-18 22:35:23 +08:00
committed by GitHub
parent f947bd1d1e
commit 2cd1b5daf9
182 changed files with 489 additions and 589 deletions
@@ -20,7 +20,7 @@ class AccessNotFoundError extends Error {
this.name = "AccessNotFoundError"
}
toString() {
override toString() {
return `${this.name}: ${this.message} at ${this.path}`
}
}
@@ -88,6 +88,7 @@ export const ShadowDOM: FC<
const [uiFont, usePointerCursor] = useUISettingKeys(["uiFontFamily", "usePointerCursor"])
return (
// @ts-expect-error
<root.div {...rest}>
<ShadowDOMContext.Provider value={true}>
<div
@@ -150,7 +151,7 @@ function getLinkedStaticStyleSheets() {
}
cssArray.push({
cssText: cacheCssTextMap[sheet.href],
cssText: cacheCssTextMap[sheet.href]!,
ref: $link,
})
}
@@ -46,7 +46,7 @@ export function FeedPreview(props: {
<div
className={cn(
"mx-auto mt-12 flex w-full flex-col items-center p-4 lg:p-0",
views[view].gridMode ? "max-w-full" : "max-w-prose",
views[view]!.gridMode ? "max-w-full" : "max-w-prose",
)}
>
<FeedIcon
@@ -73,7 +73,7 @@ export function FeedPreview(props: {
<div
className={cn(
"w-full pb-12 pt-8",
views[view].gridMode
views[view]!.gridMode
? "grid grid-cols-2 gap-4 md:grid-cols-3 lg:grid-cols-4"
: "flex max-w-3xl flex-col gap-6",
)}
@@ -84,8 +84,8 @@ export const useScrollTracking = (
// calculate the range of data-container-top between each two headings
const titleBetweenPositionTopRangeMap = [] as [number, number][]
for (let i = 0; i < toc.length - 1; i++) {
const { $heading } = toc[i]
const $nextHeading = toc[i + 1].$heading
const { $heading } = toc[i]!
const $nextHeading = toc[i + 1]!.$heading
const headingTop =
Number.parseInt($heading.dataset["containerTop"] || "0") || getElementTop($heading)
@@ -391,9 +391,9 @@ const PlayProgressBar = () => {
setCurrentDragging(true)
}}
onValueChange={(value) => {
setDragTime(value[0])
setDragTime(value[0]!)
startTransition(() => {
controls.seek(value[0])
controls.seek(value[0]!)
})
}}
onValueCommit={() => {
@@ -12,7 +12,7 @@ export const VolumeSlider: FC<{
orientation="vertical"
value={[volume ?? 0.8]}
onValueChange={(values) => {
onVolumeChange?.(values[0])
onVolumeChange?.(values[0]!)
}}
>
<Slider.Track className="relative w-1 grow rounded bg-zinc-500">
@@ -13,7 +13,7 @@ export const usePreviewMedia = (children?: React.ReactNode) => {
return useCallback(
(media: PreviewMediaProps[], initialIndex = 0) => {
if (isMobile()) {
window.open(replaceImgUrlIfNeed(media[initialIndex].url))
window.open(replaceImgUrlIfNeed(media[initialIndex]!.url))
return
}
present({
@@ -209,8 +209,8 @@ export const PreviewMediaContent: FC<{
if (media.length === 0) return null
if (media.length === 1) {
const src = media[0].url
const { type } = media[0]
const src = media[0]!.url
const { type } = media[0]!
const isVideo = type === "video"
return (
<Wrapper src={src} showActions={!isVideo} sideContent={children}>
@@ -225,23 +225,23 @@ export const PreviewMediaContent: FC<{
/>
) : (
<FallbackableImage
fallbackUrl={media[0].fallbackUrl}
fallbackUrl={media[0]!.fallbackUrl}
containerClassName="w-auto"
className="h-full w-auto object-contain"
alt="cover"
src={src}
height={media[0].height}
width={media[0].width}
blurhash={media[0].blurhash}
height={media[0]!.height}
width={media[0]!.width}
blurhash={media[0]!.blurhash}
haveSideContent={!!children}
/>
)}
</Wrapper>
)
}
const isVideo = currentMedia.type === "video"
const isVideo = currentMedia!.type === "video"
return (
<Wrapper src={currentMedia.url} showActions={!isVideo} sideContent={children}>
<Wrapper src={currentMedia!.url} showActions={!isVideo} sideContent={children}>
<div className="size-full overflow-hidden" ref={emblaRef}>
<div className="flex size-full">
{media.map((med) => (
@@ -43,7 +43,7 @@ export function PullToRefresh({
) as HTMLElement
if (!scrollContainer) return
const touchY = e.touches[0].clientY
const touchY = e.touches[0]!.clientY
setStartY(touchY)
if (scrollContainer.scrollTop <= 0) {
@@ -56,7 +56,7 @@ export function PullToRefresh({
const touchMoveHandler = (e: TouchEvent) => {
if (!shouldAllowPull || isRefreshing) return
const y = e.touches[0].clientY
const y = e.touches[0]!.clientY
const delta = y - startY
if (delta > 0) {