protomaps-leaflet icon indicating copy to clipboard operation
protomaps-leaflet copied to clipboard

Symbolizers should not take any; should take duck-typed option bags

Open bdon opened this issue 4 years ago • 3 comments

This would add helpful type and exhaustiveness checking for those writing rules in TypeScript.

bdon avatar Sep 30 '21 05:09 bdon

Had to revert this as it is too restrictive for function attributes. It is important to let the user distinguish between a function that takes (z,f) vs just (z) - in the 2nd case certain Symbolizers can optimize by doing less context mutating. Getting this to work with the type system is quite a puzzle. Until then function attributes should generally be specified with a full signature like (z:number, f:Feature):string for type safety and exhaustiveness checks.

bdon avatar Sep 30 '21 11:09 bdon

Possible approach by @nf-s : https://github.com/protomaps/protomaps.js/pull/68#issuecomment-956002443

bdon avatar Nov 02 '21 07:11 bdon

The current solution is, when writing rules in TypeScript, any attribute function has signature (zoom: number, feature?: Feature).

In terms of library core values, I see two happy paths:

  • Via a "traditional" script-includes, with rules written in plain JavaScript. The distinction between (z,f?) and (z,f) is irrelevant here because the types are gone.
  • using a bundler, protomaps as an es6 module dependency with TypeScript. There is a small ergonomics issue - having to use ? everywhere f is referenced. This annoyance seems like an acceptable tradeoff in the case you care about typing.

bdon avatar Nov 02 '21 07:11 bdon

closed by https://github.com/protomaps/protomaps-leaflet/commit/bbe8075aa741765b462668a6d9ec47cf111ab766

bdon avatar Jan 26 '24 07:01 bdon