Skip to content

fix!: improve types for {set,set}LayoutProperty, {set,set}PaintProperty to be the actual type instead of string/any#7481

Open
CommanderStorm wants to merge 12 commits intomaplibre:mainfrom
CommanderStorm:tighter-types
Open

fix!: improve types for {set,set}LayoutProperty, {set,set}PaintProperty to be the actual type instead of string/any#7481
CommanderStorm wants to merge 12 commits intomaplibre:mainfrom
CommanderStorm:tighter-types

Conversation

@CommanderStorm
Copy link
Copy Markdown
Member

Should remove a bunch of incorrect code looking at our codebase alone.

Definitively breaking given how many issues we had with this in our codebase too though.

tsc slows down a bit because of this, but they are working on this part, so likely fine.

@CommanderStorm CommanderStorm requested a review from Copilot April 16, 2026 19:14
@CommanderStorm CommanderStorm marked this pull request as ready for review April 16, 2026 19:14
@CommanderStorm CommanderStorm marked this pull request as draft April 16, 2026 19:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR tightens TypeScript typings for runtime styling APIs so set/get{Layout,Paint}Property use style-spec-derived property keys and value types instead of string/any, aligning the public API with the MapLibre Style Specification.

Changes:

  • Narrow Map and Style set/getPaintProperty + set/getLayoutProperty to keyof AllPaintProperties/AllLayoutProperties with corresponding value types.
  • Update StyleLayer property accessors/mutators to use the same typed keys/values and add typed entries for global-state paint ref tracking.
  • Adjust internal initialization paths to satisfy the stricter key/value typing.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/ui/map.ts Updates Map styling APIs to be generic over AllPaintProperties/AllLayoutProperties keys and values.
src/style/style_layer.ts Propagates typed paint/layout property keys through StyleLayer getters/setters and global-state ref tracking.
src/style/style.ts Updates Style styling APIs to typed keys/values and threads those types through paint/layout update helpers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/style/style_layer.ts Outdated
Comment thread src/style/style.ts
Comment thread src/style/style_layer.ts Outdated
return this._transitionablePaint.getTransition(baseName) as AllPaintProperties[K];
} else {
if (name === 'visibility' || this._unevaluatedLayout?.hasProperty(name)) {
if (this._unevaluatedLayout?.hasProperty(name)) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

now a ts error.. not sure if we want to keep these errors, this will error in TS code, but won't in js

Comment thread src/style/style_layer.ts

for (const property in layer.paint) {
this.setPaintProperty(property, layer.paint[property], {validate: false});
this.setPaintProperty(property as keyof AllPaintProperties, layer.paint[property as keyof typeof layer.paint], {validate: false});
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

all of these are nessary because for..in does not narrow the type for some reason

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah, this sucks,not sure why typescript traspiler doesnt do that...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

there is a long issue. Marked as not planned.
For some reason, objects in JS don't have fixed keys or something and somehow keys may apear??

So string is the only valid key apparently??

Comment thread src/style/style_layer.test.ts
Comment thread src/style/style_layer.test.ts Outdated
Comment thread src/style/style_layer.ts Outdated
return this._transitionablePaint.getTransition(baseName) as AllPaintProperties[K];
} else {
if (name === 'visibility' || this._unevaluatedLayout?.hasProperty(name)) {
if (this._unevaluatedLayout?.hasProperty(name)) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are you sure about this condition change? I think it was there delibery, wasn't it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The other code now also triggers a TS error.
So not sure.. We can keep it if I as any, but that sounds hacky..

I added this because TS was "string".

@HarelM
Copy link
Copy Markdown
Collaborator

HarelM commented Apr 17, 2026

I'm not really sure this is a breaking change to be honest, if your are passing incorrect values this should help you.
But I understand the concern, since we are planning a breaking change version this should be part of it.
I'll think about starting a first pre-release next week maybe.

Comment thread src/style/style_layer.test.ts Outdated
Comment thread src/style/style_layer.ts Outdated
Comment thread src/style/style_layer.ts Outdated
@CommanderStorm CommanderStorm added this to the 6.0 milestone Apr 17, 2026
@CommanderStorm
Copy link
Copy Markdown
Member Author

I'm not really sure this is a breaking change to be honest

technically not, but it will break lots of people who are using this wrong.
The previous warnings was simple to ignore...

@CommanderStorm CommanderStorm requested a review from HarelM April 17, 2026 21:59
@CommanderStorm CommanderStorm marked this pull request as ready for review April 17, 2026 21:59
Comment thread src/style/style_layer.ts Outdated
Comment thread src/ui/map.ts
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 18, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.80%. Comparing base (7499aa3) to head (87c05db).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7481      +/-   ##
==========================================
- Coverage   92.80%   92.80%   -0.01%     
==========================================
  Files         290      290              
  Lines       24087    24055      -32     
  Branches     5099     5086      -13     
==========================================
- Hits        22354    22324      -30     
+ Misses       1733     1731       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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