Skip to content

Conversation

@mfedderly
Copy link
Collaborator

Benchmarks were mixed, but performance is pretty much the same before/after.

throw new Error("weight must be a number");
}

box = box ?? bbox(points);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ the defaults got pushed above, but the bbox(points) call has to be after the falsy check for points or we lose the useful error message from the validation.

});
// write interpolated value for each grid point
var newFeature = clone(gridFeature);
newFeature.properties ??= {};
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the below line, the properties could have been null from the types, so we just make sure its there before proceeding.

* var addToMap = [grid];
*/
function interpolate(points, cellSize, options) {
function interpolate<T extends "point" | Grid>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you reckon about changing this to:

function interpolate<T extends Grid = "square">(

"point" is an element of the Grid union anyway, so no need to list it separately. This still seems to allow the conditional return type determination at the end of the function to work.

And I noticed if gridType is left empty, with the current definition the return type is Point | Polygon. However our runtime default is square which unambiguously infers Polygon. Setting that for the template default lets TS narrow the return type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch that's a nice improvement

Copy link
Member

@smallsaucepan smallsaucepan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @mfedderly. One more step towards TS throughout 🎉

@mfedderly mfedderly merged commit a954bf9 into master Dec 14, 2025
4 checks passed
@mfedderly mfedderly deleted the mf/turf-interpolate-ts branch December 14, 2025 11:46
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.

3 participants