Skip to content

[#74] Fix 16 TS type casting errors in swe-common-parser.ts #76

@Sam-Bolling

Description

@Sam-Bolling

Problem Overview

The file src/ogc-api/csapi/parsers/swe-common-parser.ts has 16 TypeScript errors related to type casting Record<string, unknown> to specific SWE Component types.

Child of #74

Error Pattern

All 16 errors follow this pattern:

error TS2352: Conversion of type 'Record<string, unknown>' to type 'XComponent' may be a mistake because neither type sufficiently overlaps with the other.

Affected Lines & Components

  • Line 11-12: Missing exports AnyDataComponent, DataComponent
  • Line 76: QuantityComponent
  • Line 91: CountComponent
  • Line 106: BooleanComponent
  • Line 121: TextComponent
  • Line 136: CategoryComponent
  • Line 155: TimeComponent
  • Line 174: QuantityRangeComponent
  • Line 189: CountRangeComponent
  • Line 204: CategoryRangeComponent
  • Line 223: TimeRangeComponent
  • Line 451: DataArrayComponent
  • Line 498: MatrixComponent
  • Line 545: DataStreamComponent
  • Line 560: GeometryComponent

Root Cause

TypeScript can't verify that Record<string, unknown> objects actually match the required Component type structure. The types require specific properties (type, definition, label, uom, etc.) but the parser is casting generic objects.

Solution Options

Option 1: Cast through unknown first (safest)

return parsed as unknown as QuantityComponent;

Option 2: Add type guards to validate structure before casting

Option 3: Export missing types AnyDataComponent and DataComponent from simple-components.ts

Recommended: Combination of Option 1 (immediate fix) and Option 2 (proper validation)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions