chore: enable noUncheckedIndexedAccess, better type check (#2608)
This commit is contained in:
@@ -158,7 +158,7 @@ export const DiscoverFeedForm = ({
|
||||
const ret = {}
|
||||
if (!route.parameters) return ret
|
||||
for (const key in route.parameters) {
|
||||
const params = normalizeRSSHubParameters(route.parameters[key])
|
||||
const params = normalizeRSSHubParameters(route.parameters[key]!)
|
||||
if (!params) continue
|
||||
ret[key] = params.default
|
||||
}
|
||||
@@ -218,7 +218,7 @@ export const DiscoverFeedForm = ({
|
||||
toast.error(err.message)
|
||||
const idx = keys.findIndex((item) => item.name === err.param)
|
||||
|
||||
form.setFocus(keys[idx === 0 ? 0 : idx - 1].name, {
|
||||
form.setFocus(keys[idx === 0 ? 0 : idx - 1]!.name, {
|
||||
shouldSelect: true,
|
||||
})
|
||||
}
|
||||
@@ -249,7 +249,7 @@ export const DiscoverFeedForm = ({
|
||||
)}
|
||||
<form className="flex flex-col gap-4" onSubmit={form.handleSubmit(onSubmit)} ref={formElRef}>
|
||||
{keys.map((keyItem) => {
|
||||
const parameters = normalizeRSSHubParameters(route.parameters?.[keyItem.name])
|
||||
const parameters = normalizeRSSHubParameters(route.parameters?.[keyItem.name]!)
|
||||
|
||||
const formRegister = form.register(keyItem.name)
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ const info: Record<
|
||||
|
||||
type DiscoverSearchData = Awaited<ReturnType<typeof apiClient.discover.$post>>["data"]
|
||||
export function DiscoverForm({ type = "search" }: { type?: string }) {
|
||||
const { prefix, default: defaultValue } = info[type]
|
||||
const { prefix, default: defaultValue } = info[type]!
|
||||
const form = useForm<z.infer<typeof formSchema>>({
|
||||
resolver: zodResolver(formSchema),
|
||||
defaultValues: {
|
||||
@@ -99,7 +99,7 @@ export function DiscoverForm({ type = "search" }: { type?: string }) {
|
||||
const { present, dismissAll } = useModalStack()
|
||||
|
||||
function onSubmit(values: z.infer<typeof formSchema>) {
|
||||
if (info[type].showModal) {
|
||||
if (info[type]!.showModal) {
|
||||
const defaultView = getSidebarActiveView() as FeedViewType
|
||||
present({
|
||||
title: t("feed_form.add_feed"),
|
||||
@@ -128,7 +128,7 @@ export function DiscoverForm({ type = "search" }: { type?: string }) {
|
||||
}
|
||||
const isValidPrefix = prefix.find((p) => trimmedKeyword.startsWith(p))
|
||||
if (!isValidPrefix) {
|
||||
form.setValue("keyword", prefix[0])
|
||||
form.setValue("keyword", prefix[0]!)
|
||||
return
|
||||
}
|
||||
if (trimmedKeyword.startsWith(`${isValidPrefix}${isValidPrefix}`)) {
|
||||
@@ -208,7 +208,7 @@ export function DiscoverForm({ type = "search" }: { type?: string }) {
|
||||
name="keyword"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>{t(info[type]?.label)}</FormLabel>
|
||||
<FormLabel>{t(info[type]?.label!)}</FormLabel>
|
||||
<FormControl>
|
||||
<Input autoFocus {...field} onChange={handleKeywordChange} />
|
||||
</FormControl>
|
||||
@@ -254,7 +254,7 @@ export function DiscoverForm({ type = "search" }: { type?: string }) {
|
||||
)}
|
||||
<div className="center flex" data-testid="discover-form-actions">
|
||||
<Button disabled={!form.formState.isValid} type="submit" isLoading={mutation.isPending}>
|
||||
{info[type].showModal ? t("discover.preview") : t("words.search")}
|
||||
{info[type]!.showModal ? t("discover.preview") : t("words.search")}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -29,7 +29,7 @@ export const RecommendationCard: FC<RecommendationCardProps> = memo(
|
||||
const maintainers = new Set<string>()
|
||||
const categories = new Set<string>()
|
||||
for (const route in data.routes) {
|
||||
const routeData = data.routes[route]
|
||||
const routeData = data.routes[route]!
|
||||
if (routeData.maintainers) {
|
||||
routeData.maintainers.forEach((m) => maintainers.add(m))
|
||||
}
|
||||
@@ -89,17 +89,17 @@ export const RecommendationCard: FC<RecommendationCardProps> = memo(
|
||||
content: () => (
|
||||
<RecommendationContent
|
||||
routePrefix={routePrefix}
|
||||
route={data.routes[route]}
|
||||
route={data.routes[route]!}
|
||||
/>
|
||||
),
|
||||
icon: (
|
||||
<FeedIcon className="size-4" size={16} siteUrl={`https://${data.url}`} />
|
||||
),
|
||||
title: `${data.name} - ${data.routes[route].name}`,
|
||||
title: `${data.name} - ${data.routes[route]!.name}`,
|
||||
})
|
||||
}}
|
||||
>
|
||||
{data.routes[route].name}
|
||||
{data.routes[route]!.name}
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
|
||||
@@ -29,11 +29,11 @@ export function DiscoverRSS3() {
|
||||
|
||||
return (
|
||||
<>
|
||||
{data?.rss3.routes && (
|
||||
{data?.rss3!.routes && (
|
||||
<div className="w-full max-w-[540px]">
|
||||
<DiscoverFeedForm
|
||||
routePrefix="rss3"
|
||||
route={data.rss3.routes[Object.keys(data.rss3.routes)[0]]}
|
||||
route={data.rss3.routes[Object.keys(data.rss3.routes)[0]!]!}
|
||||
noDescription
|
||||
submitButtonClassName="justify-center"
|
||||
/>
|
||||
|
||||
@@ -67,11 +67,11 @@ export function DiscoverTransform() {
|
||||
|
||||
return (
|
||||
<>
|
||||
{data?.rsshub.routes && (
|
||||
{data?.rsshub!.routes && (
|
||||
<div className="w-full max-w-[540px]">
|
||||
<DiscoverFeedForm
|
||||
routePrefix="rsshub"
|
||||
route={data?.rsshub.routes["/transform/html/:url/:routeParams"]}
|
||||
route={data?.rsshub.routes["/transform/html/:url/:routeParams"]!}
|
||||
routeParams={transformRouteParams}
|
||||
noDescription
|
||||
submitButtonClassName="justify-center"
|
||||
|
||||
@@ -27,11 +27,11 @@ export function DiscoverUser() {
|
||||
|
||||
return (
|
||||
<>
|
||||
{data?.follow.routes && (
|
||||
{data?.follow!.routes && (
|
||||
<div className="w-full max-w-[540px]">
|
||||
<DiscoverFeedForm
|
||||
routePrefix="follow"
|
||||
route={data.follow.routes[Object.keys(data.follow.routes)[0]]}
|
||||
route={data.follow.routes[Object.keys(data.follow.routes)[0]!]!}
|
||||
noDescription
|
||||
submitButtonClassName="justify-center"
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user