fix(typecheck): add proper type parameters to useState(null) hooks#1513
Conversation
When useState(null) is used for state that later accepts string, boolean, or number values, TypeScript infers the state type as null, making the setter reject non-null values (TS2345, TS2322). This adds explicit type parameters to 11 files in the simplest cases: string, boolean, number, and known string unions. components/mcp/MCPReconnect.tsx string | null commands/btw/btw.tsx string | null (error + response) commands/tag/tag.tsx string | null (sessionId) commands/rate-limit-options/ ReactNode | null commands/thinkback/thinkback.tsx string | null, boolean | null components/TeleportError.tsx TeleportLocalErrorType | null components/TeleportRepoMismatchDialog string | null components/DesktopHandoff.tsx string | null components/ThinkingToggle.tsx boolean | null components/AutoUpdaterWrapper.tsx boolean | null (2 states) components/PromptInputFooterLeftSide number | null Complex object types (GroveConfig, EnvironmentResource, etc.) and deeply multi-state components (LogSelector, PluginSettings, Doctor) are deferred to follow-up PRs. Refs: Gitlawb#1486
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (11)
📜 Recent review details⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
🧰 Additional context used📓 Path-based instructions (1)**/*⚙️ CodeRabbit configuration file
Files:
🔇 Additional comments (11)
📝 WalkthroughWalkthroughTypeScript type annotations are added to React state declarations across 11 component files. Each ChangesuseState Type Annotations
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 6 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
jatmn
left a comment
There was a problem hiding this comment.
Thanks for the contribution. I do not see any actionable issues from my review.
…itlawb#1513) When useState(null) is used for state that later accepts string, boolean, or number values, TypeScript infers the state type as null, making the setter reject non-null values (TS2345, TS2322). This adds explicit type parameters to 11 files in the simplest cases: string, boolean, number, and known string unions. components/mcp/MCPReconnect.tsx string | null commands/btw/btw.tsx string | null (error + response) commands/tag/tag.tsx string | null (sessionId) commands/rate-limit-options/ ReactNode | null commands/thinkback/thinkback.tsx string | null, boolean | null components/TeleportError.tsx TeleportLocalErrorType | null components/TeleportRepoMismatchDialog string | null components/DesktopHandoff.tsx string | null components/ThinkingToggle.tsx boolean | null components/AutoUpdaterWrapper.tsx boolean | null (2 states) components/PromptInputFooterLeftSide number | null Complex object types (GroveConfig, EnvironmentResource, etc.) and deeply multi-state components (LogSelector, PluginSettings, Doctor) are deferred to follow-up PRs. Refs: Gitlawb#1486
Summary
Refs #1486.
Adds explicit type parameters to
useState(null)calls where the setter later receives string, boolean, number, or known string-union values. TypeScript infers the state type asnull, causing TS2345/TS2322 errors when passing non-null values to the setter.What changed
Each
useState(null)was changed touseState<Type | null>(null)whereTypematches the actual values passed to the setter:commands/btw/btw.tsxresponse,errorstring | nullcommands/mcp/MCPReconnect.tsxerrorstring | nullcommands/rate-limit-options/rate-limit-options.tsxsubCommandJSXReact.ReactNode | nullcommands/tag/tag.tsxsessionIdstring | nullcommands/thinkback/thinkback.tsxinstallError,skillDir,hasGeneratedstring | null,string | null,boolean | nullcomponents/AutoUpdaterWrapper.tsxuseNativeInstaller,isPackageManagerboolean | nullcomponents/DesktopHandoff.tsxerrorstring | nullcomponents/PromptInput/PromptInputFooterLeftSide.tsxremainingSecondsnumber | nullcomponents/TeleportError.tsxcurrentErrorTeleportLocalErrorType | nullcomponents/TeleportRepoMismatchDialog.tsxerrorMessagestring | nullcomponents/ThinkingToggle.tsxconfirmationPendingboolean | nullWhy
useState(null)infers the state type asnull, makingsetX(someString)a type error. Adding the explicit type parameter is the canonical React fix. It does not change runtime behavior — the state still initializes asnull.Complex object types (
GroveConfig | null,EnvironmentResource | null,LogTreeNode | null, etc.) and deeply multi-state components (LogSelector.tsx,PluginSettings.tsx,Doctor.tsx) are deferred to follow-up PRs to keep this review manageable.Validation
git diff --check— passedbun run typecheck— zeroSetStateAction<null>errors in modified files (was ~22)Reactalready imported inrate-limit-options.tsx(no new imports needed)TeleportLocalErrorTypealready defined and exported inTeleportError.tsxSummary by CodeRabbit