fix(web): clear the 84 type errors blocking check-types - #1571
Open
rajarshidattapy wants to merge 2 commits into
Open
fix(web): clear the 84 type errors blocking check-types#1571rajarshidattapy wants to merge 2 commits into
rajarshidattapy wants to merge 2 commits into
Conversation
`apps/web` extends a tsconfig with `noUncheckedIndexedAccess`, so index
access and a few genuine defects had accumulated behind a gate that has
never been green.
Most of it traced to one expression: `useProject().selectedProject` was
`normalizedProjects[0]`, typed `string | undefined` even though the array is
never empty. Defaulting it to the same tag the array falls back to fixed ~20
errors across chat, add-document, app-experience, quick-note-card and the
note modals in one line.
The rest:
- orbit-memory: type `ring` as `0 | 1` and RR/SPEED as tuples so ring lookups
stay `number`, iterate INTEG with `.entries()`, guard the comet refs, and
fall back to an empty icon when a node has no key
- memory-graph `use-graph-data` and `graph-card`: iterate with `.entries()`
and skip edges whose endpoints are missing instead of indexing blind
- chat history buckets and user initials: optional access on fixed-shape
arrays that TypeScript cannot narrow
- `stores/chat`: drop the `msgA.content !== msgB.content` comparison —
UIMessage keeps its text in `parts`, so both sides were always undefined —
and type the conversations fallback so entries aren't `unknown`
- `useResetOrganization`: `retry: 0`, since the object form of RetryOptions
needs type/baseDelay/maxDelay
- SyncLogoIcon: accept the `style` prop timeline-view already passes it
One real bug surfaced on the way: the iOS-shortcut mutation in settings
returned `res.key` from `authClient.apiKey.create()`, which resolves to
`{ data, error }`. The key was always undefined, so the modal showed nothing
and the clipboard copy had nothing to copy. It now unwraps the result the same
way the Raycast mutation right below it does.
Comment on lines
+155
to
+157
| if (res.error) | ||
| throw new Error(res.error.message ?? "Failed to create API key") | ||
| if (!res.data?.key) throw new Error("API key missing from response") |
There was a problem hiding this comment.
The 'Exception handling' rule states: 'Include any supporting data as the cause argument instead of inlining into the string.' Here, res.error.message is being inlined directly into the error message string: throw new Error(res.error.message ?? "Failed to create API key"). The supporting data (res.error) should instead be passed as the cause option. For example:
throw new Error("Failed to create API key", { cause: res.error })Similarly, the second throw on line 157 is acceptable as-is since there's no additional data, but the first throw clearly violates this rule.
Suggested change
| if (res.error) | |
| throw new Error(res.error.message ?? "Failed to create API key") | |
| if (!res.data?.key) throw new Error("API key missing from response") | |
| if (res.error) | |
| throw new Error("Failed to create API key", { cause: res.error }) | |
| if (!res.data?.key) throw new Error("API key missing from response") | |
Spotted by Graphite (based on custom rule: TypeScript style guide (Google))
Is this helpful? React 👍 or 👎 to let us know.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1544
Result
cd apps/web && bunx tsc --noEmit: 84 → 3, and the 3 that remain are the@repo/lib/constantsalias errors from #1548, already fixed in #1569. With that branch applied on top I get 0 locally, so the two together turn the gate green for@repo/web.packages/memory-graphstill reports 0 andpackages/uistill reports its pre-existing 23 (#1542) — neither changed.One expression accounted for a quarter of it
useProject().selectedProjectwasnormalizedProjects[0], sostring | undefined— even though the line above guarantees the array is non-empty:That one-line default cleared ~20 errors across
stores/chat,chat/index,add-document,app-experience,quick-note-card,fullscreen-note-modalandhome-chat-composer, all of which pass the project id into functions typedstring.The rest
orbit-memory.tsx(27).ringis now0 | 1andRR/SPEEDare tuples, so ring lookups staynumber;INTEGis iterated with.entries(); the comet/gradient refs are captured and skipped when absent rather than indexed blind; a node without akeyrenders an empty glyph instead ofundefinedHTML.use-graph-data.ts(15) andgraph-card.tsx(4)..entries()for the document spiral, and edges whose endpoints are missing are skipped instead of pushingundefinedcoordinates.stores/chat.ts. Removedif (msgA.content !== msgB.content) return false—UIMessagekeeps its text inparts, so this comparedundefinedwithundefinedon every call and never fired; thepartscomparison directly below is the real check. Also typed the conversations fallback soObject.entriesyieldsConversationRecordinstead ofunknown.useResetOrganization.retry: { attempts: 0 }→retry: 0; the object form ofRetryOptionsrequirestype/baseDelay/maxDelay, the number form is exactly "no retries".SyncLogoIcon. Accepts thestyleprop thattimeline-view.tsxwas already passing it.A real bug, not a strictness artifact
components/settings/integrations.tsxreturnedres.keyfromauthClient.apiKey.create(), which resolves to{ data, error }.res.keywas alwaysundefined, so the iOS-shortcut flow setundefinedinto the key modal and handedundefinedtonavigator.clipboard.writeText. It now unwraps the result exactly ascreateRaycastApiKeyMutationtwenty lines below already does. This is #1541.On the approach
The issue suggests aligning the shared-package tsconfigs with the app's strictness. I fixed the code instead:
packages/memory-graph/src/hooks/use-graph-data.tsis compiled byapps/webfrom source, so making it index-safe is what actually removes the errors, and flippingnoUncheckedIndexedAccesson in that package would only surface more of the same in files web doesn't compile. Looseningapps/webwas the other option and would have buried the three genuine defects above.Nothing here changes runtime behavior except the API-key fix. The unreachable
?? defaultTag, the removed always-false comparison, and the?.guards on fixed-size arrays are all no-ops at runtime.Verification
bun testinapps/web: 51 pass / 0 fail.biome ci --changedexits 0.