Skip to content

feat(layers) Tighten layer prop types#10024

Merged
Pessimistress merged 1 commit intomasterfrom
x/strict-types
Feb 20, 2026
Merged

feat(layers) Tighten layer prop types#10024
Pessimistress merged 1 commit intomasterfrom
x/strict-types

Conversation

@Pessimistress
Copy link
Collaborator

Background

In the current release, when supplying a constant array to a layer prop such as *Color, you get the following type error:

The type 'readonly [255, 0, 0, 255]' is 'readonly' and cannot be assigned to the mutable type '[number, number, number, number]'.

In reality, our layers do not mutate user-supplied data. This PR marks all layer props that expect array values as readonly. It will continue to work with dynamically constructed values, but also accept constants.

image

Change list

  • Make Color and Position types readonly
  • Make other prop values that are array or array accessors readonly, e.g. normals, scales, domains
  • Type changes necessary to pass type check
  • fix: MultiIconLayer was mutating the incoming outlineColor

Copy link
Collaborator

@chrisgervang chrisgervang left a comment

Choose a reason for hiding this comment

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

This seems like a good idea. Is there any world where an extension mutates a users prop? I suppose that'd be rare and they could cast to unknown first to workaround it

@coveralls
Copy link

Coverage Status

coverage: 91.056% (-0.008%) from 91.064%
when pulling 7097c55 on x/strict-types
into 224e1b6 on master.

@Pessimistress
Copy link
Collaborator Author

@chrisgervang on principal we should not mutate user input. When we process user data we always make a copy of it.

@Pessimistress Pessimistress merged commit 9b4f613 into master Feb 20, 2026
5 checks passed
@Pessimistress Pessimistress deleted the x/strict-types branch February 20, 2026 20:43
Pessimistress added a commit that referenced this pull request Feb 21, 2026
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