Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enable noUncheckedIndexedAccess, better type check #2608

Merged
merged 6 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"vscode-languagedetection": "npm:@vscode/vscode-languagedetection@^1.0.22"
},
"devDependencies": {
"@follow/types": "workspace:*",
"@types/js-yaml": "4.0.9",
"@types/node": "^22.10.1",
"electron": "33.2.0",
Expand Down
4 changes: 2 additions & 2 deletions apps/main/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const detectingWindows11 = () => {
if (!isWindows) return false

const release = os.release()
const majorVersion = Number.parseInt(release.split(".")[0])
const buildNumber = Number.parseInt(release.split(".")[2])
const majorVersion = Number.parseInt(release.split(".")[0]!)
const buildNumber = Number.parseInt(release.split(".")[2]!)

return majorVersion === 10 && buildNumber >= 22000
}
Expand Down
4 changes: 2 additions & 2 deletions apps/main/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const detectingWindows11 = () => {
if (!isWindows) return false

const release = os.release()
const majorVersion = Number.parseInt(release.split(".")[0])
const buildNumber = Number.parseInt(release.split(".")[2])
const majorVersion = Number.parseInt(release.split(".")[0]!)
const buildNumber = Number.parseInt(release.split(".")[2]!)

return majorVersion === 10 && buildNumber >= 22000
}
Expand Down
2 changes: 1 addition & 1 deletion apps/main/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function bootstrap() {
userAgent = userAgent.replace(/\s?Electron\/[\d.]+/, "")
userAgent = userAgent.replace(/\s?Follow\/[\d.a-zA-Z-]+/, "")
}
details.requestHeaders["User-Agent"] = userAgent
details.requestHeaders["User-Agent"] = userAgent!

// set referer and origin
if (selfRefererMatches.some((item) => details.url.startsWith(item))) {
Expand Down
4 changes: 2 additions & 2 deletions apps/main/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { initializeSentry } from "./sentry"
import { router } from "./tipc"
import { createMainWindow, getMainWindow } from "./window"

if (process.argv.length === 3 && process.argv[2].startsWith("follow-dev:")) {
if (process.argv.length === 3 && process.argv[2]!.startsWith("follow-dev:")) {
process.env.NODE_ENV = "development"
}
const isDev = process.env.NODE_ENV === "development"
Expand All @@ -36,7 +36,7 @@ export const initializeAppStage1 = () => {
if (process.defaultApp) {
if (process.argv.length >= 2) {
app.setAsDefaultProtocolClient(APP_PROTOCOL, process.execPath, [
path.resolve(process.argv[1]),
path.resolve(process.argv[1]!),
])
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion apps/main/src/lib/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const normalizeProxyUri = (userProxy: string) => {
return
}
// Only use the first proxy if there are multiple urls
const firstInput = userProxy.split(",")[0]
const firstInput = userProxy.split(",")[0]!

try {
const proxyUrl = new URL(firstInput)
Expand Down
4 changes: 2 additions & 2 deletions apps/main/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function refreshBound(window: BrowserWindow, timeout = 0) {
setTimeout(() => {
// FIXME: workaround for theme bug in full screen mode
const size = window?.getSize()
window?.setSize(size[0] + 1, size[1] + 1)
window?.setSize(size[0], size[1])
window?.setSize(size[0]! + 1, size[1]! + 1)
window?.setSize(size[0]!, size[1]!)
}, timeout)
}
2 changes: 1 addition & 1 deletion apps/main/src/modules/language-detection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const detectCodeStringLanguage = async function* (codeString: string) {
logger.debug("no model results", codeString)
return
}
const firstModelResult = adjustLanguageConfidence(modelResults[0])
const firstModelResult = adjustLanguageConfidence(modelResults[0]!)
if (firstModelResult.confidence < expectedRelativeConfidence) {
logger.debug("first model result confidence is less than expected relative confidence")
return
Expand Down
2 changes: 1 addition & 1 deletion apps/main/src/updater/custom-github-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class CustomGitHubProvider extends BaseGitHubProvider<GithubUpdateInfo> {
if (hrefElement === null) continue

// This Release's Tag
const hrefTag = hrefElement[1]
const hrefTag = hrefElement[1]!
// Get Channel from this release's tag
// If it is null, we believe it is stable version
const hrefChannel = (semver.prerelease(hrefTag)?.[0] as string) || "stable"
Expand Down
2 changes: 1 addition & 1 deletion apps/main/src/updater/hot-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const getLatestReleaseTag = async () => {

// Search the top nightly release
const nightlyRelease = json.find((item) => item.prerelease)
if (!nightlyRelease) return json[0].tag_name
if (!nightlyRelease) return json[0]!.tag_name
return nightlyRelease.tag_name
}
}
Expand Down
4 changes: 3 additions & 1 deletion apps/main/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
"compilerOptions": {
"composite": true,
"outDir": "dist",
"types": ["electron-vite/node"],
"types": ["electron-vite/node", "@follow/types/vite"],
"moduleResolution": "Bundler",
"noImplicitReturns": false,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
"baseUrl": ".",
"paths": {
"@pkg": ["../../package.json"],
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"ios:device": "expo run:ios --device",
"lint": "expo lint",
"start": "expo start --dev-client",
"typecheck": "tsc --noEmit",
"web": "expo start --web"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/components/ui/form/PickerIos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function PickerIos<T>({

const [currentValue, setCurrentValue] = useState(() => {
if (!value) {
return options[0].value
return options[0]!.value
}
return value
})
Expand Down
4 changes: 2 additions & 2 deletions apps/mobile/src/components/ui/form/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down Expand Up @@ -65,7 +65,7 @@ export function Select<T>({
}))}
onPress={(e) => {
const { index } = e.nativeEvent
handleChangeValue(options[index].value)
handleChangeValue(options[index]!.value)
}}
>
<View
Expand Down
4 changes: 2 additions & 2 deletions apps/mobile/src/components/ui/icon/fallback-icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand All @@ -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]}
>
Expand Down
14 changes: 7 additions & 7 deletions apps/mobile/src/components/ui/tabview/TabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down Expand Up @@ -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,
}
})

Expand Down
4 changes: 2 additions & 2 deletions apps/mobile/src/components/ui/toast/manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions apps/mobile/src/modules/discover/RecommendationListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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>
Expand Down
16 changes: 8 additions & 8 deletions apps/mobile/src/modules/discover/Recommendations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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]! })
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/modules/discover/SearchTabBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}}
/>
)
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/modules/feed-drawer/feed-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/modules/feed/FollowFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>>({
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/modules/login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/modules/login/social.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
8 changes: 4 additions & 4 deletions apps/mobile/src/modules/subscription/ViewTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand All @@ -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),
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/screens/(modal)/add.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Loading
Loading