Skip to content

fix(types): type geo_distance_meters as a field-name map - #367

Open
cpruijsen wants to merge 1 commit into
typesense:masterfrom
cpruijsen:fix/issue-348
Open

fix(types): type geo_distance_meters as a field-name map#367
cpruijsen wants to merge 1 commit into
typesense:masterfrom
cpruijsen:fix/issue-348

Conversation

@cpruijsen

Copy link
Copy Markdown

SearchResponseHit.geo_distance_meters is now { [key: string]: number }, keyed by the collection's geopoint field.

Fixes #348.

{ location: number } matched the geosearch docs example only because that collection's field is named location. A coordinates geopoint returns { "coordinates": 95432 } and did not type-check.

Decision

  • Chose: { [key: string]: number }
  • Alternative: { [TAttribute in keyof T]?: number } (same pattern as SearchResponseHighlight)
  • Why: Client.collections() defaults T to object, and keyof object is never, so a mapped type would make .location a type error on the untyped path the docs use. The issue asked for a string index signature first.

Test plan

  • pnpm typecheck fails without the source change and passes with it (test/geo_distance_meters.type.test.ts)
  • coordinates type-checks on a document that declares that field
  • coordinates and location type-check on the default document generic (object)

Hits key this object by the collection geopoint field, not a hardcoded `location`.
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.

Typing for geo_distance_meters is too strict

1 participant