Skip to content

fix(web): clear the 84 type errors blocking check-types - #1571

Open
rajarshidattapy wants to merge 2 commits into
supermemoryai:mainfrom
rajarshidattapy:fix/web-check-types
Open

fix(web): clear the 84 type errors blocking check-types#1571
rajarshidattapy wants to merge 2 commits into
supermemoryai:mainfrom
rajarshidattapy:fix/web-check-types

Conversation

@rajarshidattapy

Copy link
Copy Markdown
Contributor

Fixes #1544

Result

cd apps/web && bunx tsc --noEmit: 84 → 3, and the 3 that remain are the @repo/lib/constants alias 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-graph still reports 0 and packages/ui still reports its pre-existing 23 (#1542) — neither changed.

One expression accounted for a quarter of it

useProject().selectedProject was normalizedProjects[0], so string | undefined — even though the line above guarantees the array is non-empty:

const normalizedProjects = selectedProjects.length === 0 ? [defaultTag] : selectedProjects
const selectedProject = normalizedProjects[0] ?? defaultTag   // was: normalizedProjects[0]

That one-line default cleared ~20 errors across stores/chat, chat/index, add-document, app-experience, quick-note-card, fullscreen-note-modal and home-chat-composer, all of which pass the project id into functions typed string.

The rest

  • orbit-memory.tsx (27). ring is now 0 | 1 and RR/SPEED are tuples, so ring lookups stay number; INTEG is iterated with .entries(); the comet/gradient refs are captured and skipped when absent rather than indexed blind; a node without a key renders an empty glyph instead of undefined HTML.
  • use-graph-data.ts (15) and graph-card.tsx (4). .entries() for the document spiral, and edges whose endpoints are missing are skipped instead of pushing undefined coordinates.
  • Chat history buckets, user initials. Optional access on fixed-shape arrays TypeScript can't narrow.
  • stores/chat.ts. Removed if (msgA.content !== msgB.content) return falseUIMessage keeps its text in parts, so this compared undefined with undefined on every call and never fired; the parts comparison directly below is the real check. Also typed the conversations fallback so Object.entries yields ConversationRecord instead of unknown.
  • useResetOrganization. retry: { attempts: 0 }retry: 0; the object form of RetryOptions requires type/baseDelay/maxDelay, the number form is exactly "no retries".
  • SyncLogoIcon. Accepts the style prop that timeline-view.tsx was already passing it.

A real bug, not a strictness artifact

components/settings/integrations.tsx returned res.key from authClient.apiKey.create(), which resolves to { data, error }. res.key was always undefined, so the iOS-shortcut flow set undefined into the key modal and handed undefined to navigator.clipboard.writeText. It now unwraps the result exactly as createRaycastApiKeyMutation twenty 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.ts is compiled by apps/web from source, so making it index-safe is what actually removes the errors, and flipping noUncheckedIndexedAccess on in that package would only surface more of the same in files web doesn't compile. Loosening apps/web was 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 test in apps/web: 51 pass / 0 fail. biome ci --changed exits 0.

`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")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bun run check-types has never passed on main — @repo/web reports ~90 errors

1 participant