Skip to content

TypeScript: GeoShape.coordinates() missing support for Polygon geometry (number[][][]) #217

@FBenazizMT

Description

@FBenazizMT

Bug Description

The TypeScript definition for GeoShape.coordinates() is incomplete and doesn't support Polygon geometries.
https://docs.opensearch.org/latest/field-types/supported-field-types/geo-shape/#polygon

Current Type Definition

coordinates(coords: number[][] | number[]): this;

Issue

The current typing only supports:

Point: number[] → [longitude, latitude]

LineString: number[][] → [[lon, lat], [lon, lat], ...]

But it's missing support for:

Polygon: number[][][] → [[[lon, lat], [lon, lat], ...]]

Expected Type Definition

coordinates(coords: number[] | number[][] | number[][][]): this;

Reproduction

import builder from 'elastic-builder';

const polygonCoords: number[][] = [[2.415381, 49.383599], [2.413381, 49.38364]];

// This works at runtime but fails TypeScript compilation
const geoShape = builder
  .geoShape()
  .type('polygon')
  .coordinates([polygonCoords]); // ❌ TypeScript error

// Current workaround needed:
const geoShapeWorkaround = builder
  .geoShape()
  .type('polygon')
  .coordinates([polygonCoords] as any); // ✅ Works but requires cast

Environment

elastic-builder version: 3.2.0

TypeScript version: 5.9.2

Impact

This forces developers to use as any casts when working with Polygon geometries, losing type safety.

Thank you

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