You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Replace the as unknown as OgcApiCollectionInfo double cast in factory.ts:57 with a runtime type guard function that validates the collection document structure before returning it as a typed CSAPI model object.
Finding Reference: F-NEW-02 from final-project-code-review.md Severity: Minor (DESIGN) Category: Type error Implementation Branch:phase-6
Problem Statement
factory.ts line 57 contains a double cast:
collectionDocasunknownasOgcApiCollectionInfo
The upstream getCollectionDocument() returns Promise<OgcApiDocument>, but the CSAPI factory needs OgcApiCollectionInfo. These types are structurally compatible (collection documents are a superset of the generic OGC API document shape), but TypeScript can't verify the compatibility without a cast.
The as unknown as X pattern bypasses the type system entirely. If the upstream return type ever changes, the compiler won't catch the mismatch — the code will silently produce a wrong type at runtime.
Evidence:
// factory.ts line 57 (current):returnnewCSAPIQueryBuilder(collectionDocasunknownasOgcApiCollectionInfo,resourceUrls);
Impact: No functional impact today. But the double cast is a type-safety hole — if the upstream getCollectionDocument return shape ever changes, this wouldn't be caught at compile time. A type guard would catch it at runtime.
Files to Create or Modify
File
Action
Est. Lines
Purpose
src/ogc-api/csapi/factory.ts
Modify
~15 changed
Add type guard function, replace double cast
Proposed Fix
Add a type guard function in factory.ts that validates the essential properties of a collection document before treating it as OgcApiCollectionInfo:
functionisCollectionInfo(doc: unknown): doc is OgcApiCollectionInfo{return(typeofdoc==='object'&&doc!==null&&'id'indoc&&typeof(docasRecord<string,unknown>).id==='string');}
Then replace the double cast:
// Before:collectionDocasunknownasOgcApiCollectionInfo// After:if(!isCollectionInfo(collectionDoc)){thrownewEndpointError(`Collection '${collectionId}' document is not a valid OgcApiCollectionInfo`);}// collectionDoc is now narrowed to OgcApiCollectionInfo
Scope — What NOT to Touch
❌ Do NOT modify endpoint.ts — the return type of getCollectionDocument is upstream-owned
❌ Do NOT modify model.ts — the OgcApiCollectionInfo interface is upstream-owned
Task
Replace the
as unknown as OgcApiCollectionInfodouble cast infactory.ts:57with a runtime type guard function that validates the collection document structure before returning it as a typed CSAPI model object.Finding Reference: F-NEW-02 from final-project-code-review.md
Severity: Minor (DESIGN)
Category: Type error
Implementation Branch:
phase-6Problem Statement
factory.tsline 57 contains a double cast:The upstream
getCollectionDocument()returnsPromise<OgcApiDocument>, but the CSAPI factory needsOgcApiCollectionInfo. These types are structurally compatible (collection documents are a superset of the generic OGC API document shape), but TypeScript can't verify the compatibility without a cast.The
as unknown as Xpattern bypasses the type system entirely. If the upstream return type ever changes, the compiler won't catch the mismatch — the code will silently produce a wrong type at runtime.Evidence:
Impact: No functional impact today. But the double cast is a type-safety hole — if the upstream
getCollectionDocumentreturn shape ever changes, this wouldn't be caught at compile time. A type guard would catch it at runtime.Files to Create or Modify
src/ogc-api/csapi/factory.tsProposed Fix
Add a type guard function in
factory.tsthat validates the essential properties of a collection document before treating it asOgcApiCollectionInfo:Then replace the double cast:
Scope — What NOT to Touch
endpoint.ts— the return type ofgetCollectionDocumentis upstream-ownedmodel.ts— theOgcApiCollectionInfointerface is upstream-ownedindex.ts(barrel file)factory.tsAcceptance Criteria
as unknown as OgcApiCollectionInforemoved fromfactory.tsEndpointErrorthrown if the document doesn't match expected shapenpx tsc --noEmitpasses (typecheck clean)npm run lintpassesnpm run test:nodepassesnpx prettier --check src/ogc-api/csapi/factory.tspassesDependencies
Blocked by: Issue #129 (F-NEW-01 — remove
as anycast first, since both touch the same code area)Blocks: Nothing
Operational Constraints
Key constraints:
References
src/ogc-api/csapi/factory.tsline 57src/ogc-api/model.tsOgcApiCollectionInfointerface definition