Skip to content

break(meta) BREAK: Update coordEach for improved TypeScript inference - #3160

Merged
mfedderly merged 1 commit into
masterfrom
mf/meta-rework
Sep 7, 2026
Merged

mfedderly merged 1 commit into
masterfrom
mf/meta-rework

Conversation

@mfedderly

@mfedderly mfedderly commented Sep 7, 2026 •

Copy link
Copy Markdown
Collaborator

Makes several breaking API changes and improves test coverage and speed.

API Changes:

  • Now correctly exposes void | false return type which lets you short-circuit the loop. This has always existed in the JavaScript path, but was not visible through the TypeScript types
  • Changes from AllGeoJSON to just GeoJSON from @type/geojson, which are equivalent
  • The callback now returns a Position instead of number[], these are the same thing but Position comes from GeoJSON and is more specific
  • Nested GeometryCollections are officially unsupported now instead of working but behaving very strangely.

Note on the nested GeometryCollections: its a little unfortunate that GeoJSON type quietly infers that you can have nested GeometryCollections. We could narrow the TypeScript types to enforce this, but then consumers would then be forced into doing their own type narrowing before calling coordEach, which is a little annoying as well.

Implementation improvements:

  • Remove all @ts-expect-error tags from the implementation
  • Remove big var block and push allocations into the areas where they are needed
  • Break apart each GeoJSON type for clearer logic, this adds some lines but I think the logic can be made clearer because of it. excludeWrapCoord logic and incrementing the counters is now clearer because of it.
  • Loop iterators modernized where possible
  • excludeWrapCoord logic simplified
  • Interestingly there are duplicate obj.type checks, but this version benchmarks faster than factoring them out (macos / node 26)
  • Added a bit more code coverage and updated the type tests based on the breaking changes that were made

Benchmarks

before
coordEach     - point x 110,457,081 ops/sec ±1.28% (95 runs sampled)
coordEach     - points x 255,247 ops/sec ±0.62% (96 runs sampled)
coordEach     - polygon x 82,126,479 ops/sec ±1.04% (91 runs sampled)
coordEach     - polygons x 124,665 ops/sec ±0.88% (97 runs sampled)

after
coordEach     - point x 130,932,389 ops/sec ±1.88% (94 runs sampled)
coordEach     - points x 418,112 ops/sec ±0.74% (98 runs sampled)
coordEach     - polygon x 86,664,317 ops/sec ±1.28% (91 runs sampled)
coordEach     - polygons x 148,778 ops/sec ±0.29% (96 runs sampled)

@mfedderly mfedderly added this to the v8 milestone Sep 7, 2026
@mfedderly mfedderly added the backwards incompatible Exhibiting backwards incompatible behaviour, not explicitly documented. label Sep 7, 2026
@mfedderly mfedderly changed the title Update coordEach break(meta) BREAK: Update coordEach for improved TypeScript inference Sep 7, 2026
@mfedderly
mfedderly merged commit 7c36bc9 into master Sep 7, 2026
3 checks passed
@mfedderly
mfedderly deleted the mf/meta-rework branch September 7, 2026 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backwards incompatible Exhibiting backwards incompatible behaviour, not explicitly documented. @turf/meta

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant