break(helpers) tighten geometry() coordinates typing - #3166
Open
modusensus wants to merge 1 commit into
Open
modusensus wants to merge 1 commit into
modusensus wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Tightens the
coordinatesparameter ofgeometry()so TypeScript enforces the correct coordinate shape for each geometry type at compile time:"Point"→Position"LineString"/"MultiPoint"→Position[]"Polygon"/"MultiLineString"→Position[][]"MultiPolygon"→Position[][][]Resolves #2973
Breaking change
Design notes (open to feedback)
CoordinatesFor<T>is deliberately not exported. Exporting it would add a conditional type to the public API that the docs generator cannot resolve (it renders asType: anyin the README). If you'd prefer it exported for downstream generic code, that's a one-line change — happy to flip it.GeometryTypeis exported because it resolves cleanly in the generated docs, and it gives consumers a reusable name for the six geometry kindsgeometry()accepts. The name is bikesheddable (GeometryTypeName,GeometryTypeString, …).documentationgenerator renders parameter types from the TypeScript signatures rather than the@paramannotations, which is why the README showscoordinatesasCoordinatesFor<T>instead of aPosition|Position[]|…union.Changes
GeometryTypeunion and internalCoordinatesFor<T>conditional type in@turf/helpersgeometry()'s runtime logic is unchanged; a single re-broadening alias bridges the deferred generic to the per-type constructors in the switchpackages/turf-helpers/types.ts(the package's existingtest:typesconvention)pnpm run docs@turf/helpers'contributorsfield per the PR checklistChecklist
contributorsfield ofpackage.jsonFull
pnpm -r run testpassing locally across all 122 packages (the root lint suite could not run on this Windows machine due to a monorepolint Windows path bug — CI will cover it).