Skip to content

fix(frontend): type Document.metadata fields to resolve unknown→ReactNode build errors#16

Merged
SynTechRev merged 3 commits into
masterfrom
copilot/fix-document-metadata-types
Apr 13, 2026
Merged

fix(frontend): type Document.metadata fields to resolve unknown→ReactNode build errors#16
SynTechRev merged 3 commits into
masterfrom
copilot/fix-document-metadata-types

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 13, 2026

Document.metadata typed as Record<string, unknown> caused metadata.jurisdiction and metadata.year to resolve as unknown, which TypeScript strict mode rejects as ReactNode — breaking both desktop build workflows.

Changes

  • frontend/lib/types/api.ts — Introduce DocumentMetadata interface with explicit jurisdiction?: string and year?: string | number fields plus an index signature for arbitrary keys; swap Document.metadata from Record<string, unknown> to DocumentMetadata
export interface DocumentMetadata {
  jurisdiction?: string;
  year?: string | number;
  [key: string]: unknown;
}

export interface Document {
  ...
  metadata: DocumentMetadata;  // was: Record<string, unknown>
  ...
}

Fixes the type error in both DocumentDetailPanel.tsx (lines 38–49) and DocumentList.tsx (line 50) where these fields are rendered directly in JSX.

Original prompt

Problem

Both the Desktop Build and Build and Release Desktop Apps workflows are failing with the following TypeScript error:

./components/document/DocumentDetailPanel.tsx:38:11
Type error: Type 'unknown' is not assignable to type 'ReactNode'.

This occurs at frontend/components/document/DocumentDetailPanel.tsx on lines 38–42 and 45–49, where document.metadata.jurisdiction and document.metadata.year are rendered directly in JSX. These fields are typed as unknown because Document.metadata in frontend/lib/types/api.ts (line 256) is defined as Record<string, unknown>.

// Line 38-43 — metadata.jurisdiction is `unknown`
{document.metadata.jurisdiction && (
  <div>
    <div className="text-sm text-gray-600 mb-1">Jurisdiction</div>
    <div className="font-medium text-gray-900">{document.metadata.jurisdiction}</div>
  </div>
)}

// Line 45-50 — metadata.year is `unknown`
{document.metadata.year && (
  <div>
    <div className="text-sm text-gray-600 mb-1">Year</div>
    <div className="font-medium text-gray-900">{document.metadata.year}</div>
  </div>
)}

Root Cause

In frontend/lib/types/api.ts, the Document interface defines:

export interface Document {
  ...
  metadata: Record<string, unknown>;
  ...
}

This makes all metadata field accesses resolve to unknown, which TypeScript strict mode rejects as a ReactNode.

Fix

There are two acceptable approaches:

Option A (Preferred) — Type-guard the values before rendering

Cast document.metadata.jurisdiction and document.metadata.year to string using a type guard or String() conversion in DocumentDetailPanel.tsx:

{document.metadata.jurisdiction && (
  <div>
    <div className="text-sm text-gray-600 mb-1">Jurisdiction</div>
    <div className="font-medium text-gray-900">
      {String(document.metadata.jurisdiction)}
    </div>
  </div>
)}

{document.metadata.year && (
  <div>
    <div className="text-sm text-gray-600 mb-1">Year</div>
    <div className="font-medium text-gray-900">
      {String(document.metadata.year)}
    </div>
  </div>
)}

Option B (Also acceptable) — Extend the Document metadata type

Add a typed DocumentMetadata interface in frontend/lib/types/api.ts and use it in the Document interface:

export interface DocumentMetadata {
  jurisdiction?: string;
  year?: string | number;
  [key: string]: unknown;
}

export interface Document {
  document_id: string;
  title: string;
  text: string;
  metadata: DocumentMetadata;
  chunks: string[];
  checksum?: string;
  created_at: string;
}

Please apply whichever option is cleaner and ensures the TypeScript build passes. Make sure to check if any other metadata fields in DocumentDetailPanel.tsx or any other component have a similar issue and fix those too.

Files to Change

  • frontend/components/document/DocumentDetailPanel.tsx
  • Optionally: frontend/lib/types/api.ts (if Option B is chosen)

Expected Outcome

Both Desktop Build and Build and Release Desktop Apps workflows 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:

  • Failing CI/CD workflows or Actions
  • Open issues or bugs
  • Failing tests
  • Overall repo health

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

Property Details
Language Python
License MIT
Default Branch master
Created ~32 days ago
Last Push ~26 minutes ago
Visibility Public

🔴 Failing Workflows

The most critical issue is a recurring TypeScript type error that is breaking two workflows:

1. Build and Release Desktop Apps (run) — ❌ Failed

2. Desktop Build (run) — ❌ Failed

Both fail with the same error in app/documents/page.tsx at line 49:

Type error: Type '(doc: Document | null) => void' is not assignable to type '(documentId: string) => void'.
  Types of parameters 'doc' and 'documentId' are incompatible.
    Type 'string' is not assignable to type 'Document'.

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.

Copilot AI and others added 2 commits April 13, 2026 22:08
Copilot AI changed the title [WIP] Fix TypeScript error in DocumentDetailPanel rendering fix(frontend): type Document.metadata fields to resolve unknown→ReactNode build errors Apr 13, 2026
Copilot AI requested a review from SynTechRev April 13, 2026 22:10
@SynTechRev SynTechRev marked this pull request as ready for review April 13, 2026 22:16
Copilot AI review requested due to automatic review settings April 13, 2026 22:16
@SynTechRev SynTechRev merged commit 866b6e5 into master Apr 13, 2026
23 of 24 checks passed
@SynTechRev SynTechRev deleted the copilot/fix-document-metadata-types branch April 13, 2026 22:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 DocumentMetadata interface with typed jurisdiction/year plus an index signature for additional keys.
  • Update Document.metadata from Record<string, unknown> to DocumentMetadata.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread frontend/lib/types/api.ts
title: string;
text: string;
metadata: Record<string, unknown>;
metadata: DocumentMetadata;
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
metadata: DocumentMetadata;
metadata: DocumentMetadata | Record<string, unknown>;

Copilot uses AI. Check for mistakes.
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.

3 participants