fix(frontend): type Document.metadata fields to resolve unknown→ReactNode build errors#16
Conversation
…Script errors Agent-Logs-Url: https://github.com/SynTechRev/ODIA/sessions/8f2e7b02-0e64-4d9a-beb6-ac6ca50e1fd8 Co-authored-by: SynTechRev <235390103+SynTechRev@users.noreply.github.com>
Agent-Logs-Url: https://github.com/SynTechRev/ODIA/sessions/8f2e7b02-0e64-4d9a-beb6-ac6ca50e1fd8 Co-authored-by: SynTechRev <235390103+SynTechRev@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Updates the frontend’s local Document type definitions to make commonly-rendered metadata fields (jurisdiction, year) strongly typed, addressing strict TypeScript JSX rendering errors in document UI components.
Changes:
- Add a new
DocumentMetadatainterface with typedjurisdiction/yearplus an index signature for additional keys. - Update
Document.metadatafromRecord<string, unknown>toDocumentMetadata.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| title: string; | ||
| text: string; | ||
| metadata: Record<string, unknown>; | ||
| metadata: DocumentMetadata; |
There was a problem hiding this comment.
Changing Document.metadata to DocumentMetadata narrows the type, but /analyze responses are still typed as AnalysisResult.metadata: Record<string, unknown>. In components/document/UploadPanel.tsx, a local Document is built with metadata: result.metadata, which will no longer be assignable (because jurisdiction/year are unknown on the Record type). To keep the types consistent and avoid introducing a new build error, consider updating AnalysisResult.metadata (and optionally AnalyzePayload.metadata) to DocumentMetadata, or explicitly normalizing/casting result.metadata when constructing a Document.
| metadata: DocumentMetadata; | |
| metadata: DocumentMetadata | Record<string, unknown>; |
Document.metadatatyped asRecord<string, unknown>causedmetadata.jurisdictionandmetadata.yearto resolve asunknown, which TypeScript strict mode rejects asReactNode— breaking both desktop build workflows.Changes
frontend/lib/types/api.ts— IntroduceDocumentMetadatainterface with explicitjurisdiction?: stringandyear?: string | numberfields plus an index signature for arbitrary keys; swapDocument.metadatafromRecord<string, unknown>toDocumentMetadataFixes the type error in both
DocumentDetailPanel.tsx(lines 38–49) andDocumentList.tsx(line 50) where these fields are rendered directly in JSX.Original prompt
Problem
Both the
Desktop BuildandBuild and Release Desktop Appsworkflows are failing with the following TypeScript error:This occurs at
frontend/components/document/DocumentDetailPanel.tsxon lines 38–42 and 45–49, wheredocument.metadata.jurisdictionanddocument.metadata.yearare rendered directly in JSX. These fields are typed asunknownbecauseDocument.metadatainfrontend/lib/types/api.ts(line 256) is defined asRecord<string, unknown>.Root Cause
In
frontend/lib/types/api.ts, theDocumentinterface defines:This makes all metadata field accesses resolve to
unknown, which TypeScript strict mode rejects as aReactNode.Fix
There are two acceptable approaches:
Option A (Preferred) — Type-guard the values before rendering
Cast
document.metadata.jurisdictionanddocument.metadata.yeartostringusing a type guard orString()conversion inDocumentDetailPanel.tsx:Option B (Also acceptable) — Extend the
Documentmetadata typeAdd a typed
DocumentMetadatainterface infrontend/lib/types/api.tsand use it in theDocumentinterface:Please apply whichever option is cleaner and ensures the TypeScript build passes. Make sure to check if any other metadata fields in
DocumentDetailPanel.tsxor any other component have a similar issue and fix those too.Files to Change
frontend/components/document/DocumentDetailPanel.tsxfrontend/lib/types/api.ts(if Option B is chosen)Expected Outcome
Both
Desktop BuildandBuild and Release Desktop Appsworkflows should pass after the fix.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Can you assess the repo to see what is necessary and what is failing?
Assistant: I'd be happy to help assess a repository! Could you please provide the repository name and owner (in the format
owner/repo)? That way I can look into what's happening with it.User: ODIA
Assistant: Could you clarify the full repository path? Is it
SynTechRev/ODIA? Also, what specifically would you like me to assess? For example:Let me know and I'll dive in!
User: SynTechRev/ODIA
Assistant: Let me gather some information about the repository simultaneously!
Assistant: Here's a full assessment of SynTechRev/ODIA:
📋 Repository Overview
master🔴 Failing Workflows
The most critical issue is a recurring TypeScript type error that is breaking two workflows:
1.
Build and Release Desktop Apps(run) — ❌ Failed2.
Desktop Build(run) — ❌ FailedBoth fail with the same error in
app/documents/page.tsxat line 49:Root Cause: A callback prop mismatch — the component expects a function that receives a
string(a document ID), but is being passed a function that receives a `Document |...This pull request was created from Copilot chat.