chore: enable noUncheckedIndexedAccess, better type check (#2608)
This commit is contained in:
@@ -33,7 +33,7 @@ export function PickerIos<T>({
|
||||
|
||||
const [currentValue, setCurrentValue] = useState(() => {
|
||||
if (!value) {
|
||||
return options[0].value
|
||||
return options[0]!.value
|
||||
}
|
||||
return value
|
||||
})
|
||||
|
||||
@@ -31,7 +31,7 @@ export function Select<T>({
|
||||
}: SelectProps<T>) {
|
||||
const [currentValue, setCurrentValue] = useState(() => {
|
||||
if (!value) {
|
||||
return options[0].value
|
||||
return options[0]!.value
|
||||
}
|
||||
return value
|
||||
})
|
||||
@@ -65,7 +65,7 @@ export function Select<T>({
|
||||
}))}
|
||||
onPress={(e) => {
|
||||
const { index } = e.nativeEvent
|
||||
handleChangeValue(options[index].value)
|
||||
handleChangeValue(options[index]!.value)
|
||||
}}
|
||||
>
|
||||
<View
|
||||
|
||||
@@ -28,7 +28,7 @@ export const FallbackIcon = ({
|
||||
const [, , , bgAccent, bgAccentLight, bgAccentUltraLight] = colors
|
||||
|
||||
const renderedText = useMemo(() => {
|
||||
const isCJK = isCJKChar(title[0])
|
||||
const isCJK = isCJKChar(title[0]!)
|
||||
return (
|
||||
<Text style={StyleSheet.flatten([styles.text, textStyle])} className={textClassName}>
|
||||
{isCJK ? title[0] : title.slice(0, 2)}
|
||||
@@ -39,7 +39,7 @@ export const FallbackIcon = ({
|
||||
return (
|
||||
<LinearGradient
|
||||
className={className}
|
||||
colors={[bgAccent, bgAccentLight, bgAccentUltraLight]}
|
||||
colors={[bgAccent!, bgAccentLight!, bgAccentUltraLight!]}
|
||||
locations={[0, 0.99, 1]}
|
||||
style={[sizeStyle, styles.container, style]}
|
||||
>
|
||||
|
||||
@@ -112,11 +112,11 @@ export const TabBar = forwardRef<ScrollView, TabBarProps>(
|
||||
indicatorPosition.value = withSpring(tabPositions[currentTab] || 0, springConfig)
|
||||
|
||||
if (tabRef.current) {
|
||||
const x = currentTab > 0 ? tabPositions[currentTab - 1] + tabWidths[currentTab - 1] : 0
|
||||
const x = currentTab > 0 ? tabPositions[currentTab - 1]! + tabWidths[currentTab - 1]! : 0
|
||||
|
||||
const isCurrentTabVisible =
|
||||
sharedPagerOffsetX.value < tabPositions[currentTab] &&
|
||||
sharedPagerOffsetX.value + tabWidths[currentTab] > tabPositions[currentTab]
|
||||
sharedPagerOffsetX.value < tabPositions[currentTab]! &&
|
||||
sharedPagerOffsetX.value + tabWidths[currentTab]! > tabPositions[currentTab]!
|
||||
|
||||
if (!isCurrentTabVisible) {
|
||||
tabRef.current.scrollTo({ x, y: 0, animated: true })
|
||||
@@ -146,17 +146,17 @@ export const TabBar = forwardRef<ScrollView, TabBarProps>(
|
||||
|
||||
// Interpolate between current and next tab positions
|
||||
const xPosition =
|
||||
tabPositions[currentIndex] +
|
||||
(tabPositions[nextIndex] - tabPositions[currentIndex]) * progress
|
||||
tabPositions[currentIndex]! +
|
||||
(tabPositions[nextIndex]! - tabPositions[currentIndex]!) * progress
|
||||
|
||||
// Interpolate between current and next tab widths
|
||||
const width =
|
||||
tabWidths[currentIndex] + (tabWidths[nextIndex] - tabWidths[currentIndex]) * progress
|
||||
tabWidths[currentIndex]! + (tabWidths[nextIndex]! - tabWidths[currentIndex]!) * progress
|
||||
|
||||
return {
|
||||
transform: [{ translateX: Math.max(xPosition, 0) }],
|
||||
width,
|
||||
backgroundColor: tabs[currentTab].activeColor || accentColor,
|
||||
backgroundColor: tabs[currentTab]!.activeColor || accentColor,
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -64,14 +64,14 @@ export class ToastManager {
|
||||
}
|
||||
|
||||
private scheduleDismiss(index: number) {
|
||||
const props = this.propsMap[index]
|
||||
const props = this.propsMap[index]!
|
||||
|
||||
if (props.duration === Infinity) {
|
||||
return
|
||||
}
|
||||
|
||||
setTimeout(async () => {
|
||||
await this.toastRefs[index].dimiss()
|
||||
await this.toastRefs[index]!.dimiss()
|
||||
this.remove(index)
|
||||
}, props.duration)
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ export const RecommendationListItem: FC<{
|
||||
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))
|
||||
}
|
||||
@@ -120,7 +120,7 @@ export const RecommendationListItem: FC<{
|
||||
/>
|
||||
<View className="absolute inset-2 items-center justify-center" pointerEvents="none">
|
||||
<Text ellipsizeMode="middle" numberOfLines={1} className="text-text whitespace-pre">
|
||||
{data.routes[route].name}
|
||||
{data.routes[route]!.name}
|
||||
</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
@@ -75,11 +75,11 @@ const Tab: TabComponent = ({ tab, ...rest }) => {
|
||||
return []
|
||||
}
|
||||
return Object.keys(data).sort((a, b) => {
|
||||
const aname = data[a].name
|
||||
const bname = data[b].name
|
||||
const aname = data[a]!.name
|
||||
const bname = data[b]!.name
|
||||
|
||||
const aRouteName = data[a].routes[Object.keys(data[a].routes)[0]].name
|
||||
const bRouteName = data[b].routes[Object.keys(data[b].routes)[0]].name
|
||||
const aRouteName = data[a]!.routes[Object.keys(data[a]!.routes)[0]!]!.name
|
||||
const bRouteName = data[b]!.routes[Object.keys(data[b]!.routes)[0]!]!.name
|
||||
|
||||
const ia = isASCII(aname) && isASCII(aRouteName)
|
||||
const ib = isASCII(bname) && isASCII(bRouteName)
|
||||
@@ -98,7 +98,7 @@ const Tab: TabComponent = ({ tab, ...rest }) => {
|
||||
const groups = keys.reduce(
|
||||
(acc, key) => {
|
||||
// A-Z -> A-Z, 0-9 -> #, other -> #, # push to the end
|
||||
const firstChar = key[0].toUpperCase()
|
||||
const firstChar = key[0]!.toUpperCase()
|
||||
if (/[A-Z]/.test(firstChar)) {
|
||||
acc[firstChar] = acc[firstChar] || []
|
||||
acc[firstChar].push(key)
|
||||
@@ -127,7 +127,7 @@ const Tab: TabComponent = ({ tab, ...rest }) => {
|
||||
if (!data) {
|
||||
continue
|
||||
}
|
||||
result.push({ key: item, data: data[item] })
|
||||
result.push({ key: item, data: data[item]! })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ const NavigationSidebar: FC<{
|
||||
(letter: string, animated = true) => {
|
||||
const index = alphabetGroups.findIndex((group) => {
|
||||
if (typeof group !== "string") return false
|
||||
const firstChar = group[0].toUpperCase()
|
||||
const firstChar = group[0]!.toUpperCase()
|
||||
const firstCharIsAlphabet = /[A-Z]/.test(firstChar)
|
||||
if (firstCharIsAlphabet) {
|
||||
return firstChar === letter
|
||||
@@ -233,7 +233,7 @@ const NavigationSidebar: FC<{
|
||||
return
|
||||
}
|
||||
|
||||
const firstChar = letter[0].toUpperCase()
|
||||
const firstChar = letter[0]!.toUpperCase()
|
||||
const firstCharIsAlphabet = /[A-Z]/.test(firstChar)
|
||||
if (firstCharIsAlphabet) {
|
||||
scrollToLetter(letter, false)
|
||||
|
||||
@@ -20,7 +20,7 @@ export const SearchTabBar: FC<{
|
||||
tabs={SearchTabs}
|
||||
currentTab={SearchTabs.findIndex((tab) => tab.value === searchType)}
|
||||
onTabItemPress={(index) => {
|
||||
setSearchType(SearchTabs[index].value as SearchType)
|
||||
setSearchType(SearchTabs[index]!.value as SearchType)
|
||||
}}
|
||||
/>
|
||||
)
|
||||
|
||||
@@ -199,7 +199,7 @@ const CategoryGrouped = memo(
|
||||
const SubscriptionItem = memo(({ id, className }: { id: string; className?: string }) => {
|
||||
const subscription = useSubscription(id)
|
||||
const unreadCount = useUnreadCount(id)
|
||||
const feed = useFeed(id)
|
||||
const feed = useFeed(id)!
|
||||
const inGrouped = !!useContext(GroupedContext)
|
||||
const view = useCurrentView()
|
||||
const { isLoading } = usePrefetchFeed(id, { enabled: !feed })
|
||||
|
||||
@@ -50,7 +50,7 @@ export function FollowFeed(props: { id: string }) {
|
||||
function FollowImpl() {
|
||||
const { id } = useLocalSearchParams()
|
||||
|
||||
const feed = useFeed(id as string)
|
||||
const feed = useFeed(id as string)!
|
||||
const isSubscribed = useSubscriptionByFeedId(feed?.id || "")
|
||||
|
||||
const form = useForm<z.infer<typeof formSchema>>({
|
||||
|
||||
@@ -96,7 +96,7 @@ const TeamsCheckBox = forwardRef<
|
||||
const runAnimation = (index: number) => {
|
||||
"worklet"
|
||||
if (index < animations.length) {
|
||||
shakeSharedValue.value = withTiming(animations[index], { duration: 100 }, () => {
|
||||
shakeSharedValue.value = withTiming(animations[index]!, { duration: 100 }, () => {
|
||||
runAnimation(index + 1)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ export function SocialLogin() {
|
||||
{Object.keys(provider)
|
||||
.filter((key) => key !== "apple" || (Platform.OS === "ios" && key === "apple"))
|
||||
.map((key) => {
|
||||
const providerInfo = provider[key]
|
||||
const providerInfo = provider[key]!
|
||||
return (
|
||||
<TouchableOpacity
|
||||
key={key}
|
||||
|
||||
@@ -38,11 +38,11 @@ export const ViewTab = () => {
|
||||
indicatorPosition.value = withSpring(tabPositions[currentView] || 0, springConfig)
|
||||
|
||||
if (tabRef.current) {
|
||||
const x = currentView > 0 ? tabPositions[currentView - 1] + tabWidths[currentView - 1] : 0
|
||||
const x = currentView > 0 ? tabPositions[currentView - 1]! + tabWidths[currentView - 1]! : 0
|
||||
|
||||
const isCurrentTabVisible =
|
||||
scrollOffsetX.current < tabPositions[currentView] &&
|
||||
scrollOffsetX.current + tabWidths[currentView] > tabPositions[currentView]
|
||||
scrollOffsetX.current < tabPositions[currentView]! &&
|
||||
scrollOffsetX.current + tabWidths[currentView]! > tabPositions[currentView]!
|
||||
|
||||
if (!isCurrentTabVisible) {
|
||||
tabRef.current.scrollTo({ x, y: 0, animated: true })
|
||||
@@ -58,7 +58,7 @@ export const ViewTab = () => {
|
||||
translateX: indicatorPosition.value + 10 + Math.abs(offset),
|
||||
},
|
||||
],
|
||||
backgroundColor: views[currentView].activeColor,
|
||||
backgroundColor: views[currentView]!.activeColor,
|
||||
width: (tabWidths[currentView] || 20) - 40 + Math.abs(offset),
|
||||
}
|
||||
})
|
||||
|
||||
@@ -46,7 +46,7 @@ import { GroupedContext, useViewPageCurrentView } from "../ctx"
|
||||
export const SubscriptionItem = memo(({ id, className }: { id: string; className?: string }) => {
|
||||
const subscription = useSubscription(id)
|
||||
const unreadCount = useUnreadCount(id)
|
||||
const feed = useFeed(id)
|
||||
const feed = useFeed(id)!
|
||||
const inGrouped = !!useContext(GroupedContext)
|
||||
const view = useViewPageCurrentView()
|
||||
const { isLoading } = usePrefetchFeed(id, { enabled: !subscription && !feed })
|
||||
|
||||
@@ -10,6 +10,7 @@ export default function Add() {
|
||||
const [url, setUrl] = useState("")
|
||||
|
||||
const label = useColor("label")
|
||||
// @ts-expect-error FIXME: use the right color
|
||||
const disabled = useColor("disabled")
|
||||
return (
|
||||
<View>
|
||||
|
||||
@@ -55,7 +55,7 @@ export default function RsshubForm() {
|
||||
if (!parsedRoute || !routePrefix) {
|
||||
return null
|
||||
}
|
||||
return <FormImpl route={parsedRoute} routePrefix={routePrefix as string} name={name} />
|
||||
return <FormImpl route={parsedRoute} routePrefix={routePrefix as string} name={name!} />
|
||||
}
|
||||
|
||||
function FormImpl({ route, routePrefix, name }: RsshubFormParams) {
|
||||
@@ -98,7 +98,7 @@ function FormImpl({ route, routePrefix, name }: RsshubFormParams) {
|
||||
const ret = {} as Record<string, string | null>
|
||||
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
|
||||
}
|
||||
@@ -128,7 +128,7 @@ function FormImpl({ route, routePrefix, name }: RsshubFormParams) {
|
||||
>
|
||||
<View className="bg-secondary-system-grouped-background mx-2 mt-2 gap-4 rounded-lg px-3 py-6">
|
||||
{keys.map((keyItem) => {
|
||||
const parameters = normalizeRSSHubParameters(route.parameters[keyItem.name])
|
||||
const parameters = normalizeRSSHubParameters(route.parameters[keyItem.name]!)
|
||||
|
||||
return (
|
||||
<View key={keyItem.name}>
|
||||
|
||||
@@ -29,7 +29,7 @@ export default function Index() {
|
||||
<Stack.Screen
|
||||
options={{
|
||||
headerShown: true,
|
||||
title: views[currentView].name,
|
||||
title: views[currentView]!.name,
|
||||
headerLeft: LeftAction,
|
||||
headerRight: RightAction,
|
||||
headerTransparent: true,
|
||||
|
||||
@@ -20,7 +20,7 @@ export const getSubscriptionByCategory = (category: string): string[] => {
|
||||
|
||||
const ids = [] as string[]
|
||||
for (const id of Object.keys(state.data)) {
|
||||
if (state.data[id].category === category) {
|
||||
if (state.data[id]!.category === category) {
|
||||
ids.push(id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ export const useSortedGroupedSubscription = (
|
||||
})
|
||||
const sortedList = [] as { category: string; subscriptionIds: string[] }[]
|
||||
for (const category of sortedCategories) {
|
||||
sortedList.push({ category, subscriptionIds: grouped[category] })
|
||||
sortedList.push({ category, subscriptionIds: grouped[category]! })
|
||||
}
|
||||
return sortedList
|
||||
}, [grouped, sortBy, sortOrder]),
|
||||
|
||||
Reference in New Issue
Block a user