mobxjs / mobx-state-tree

Full-featured reactive state management without the boilerplate
https://mobx-state-tree.js.org/
MIT License
6.9k stars 639 forks source link

Allow readonly string arrays in types.enumeration #2059

Closed jamonholmgren closed 10 months ago

jamonholmgren commented 11 months ago

Overview

This PR enhances the enumeration function types to accept both mutable (string[]) and immutable (readonly string[]) string arrays. This allows for better compatibility with as const syntax and provides a more flexible API for users.

Fixes #1314.

Changes

Impact

These changes enable developers to use as const syntax with the enumeration function without any type errors, providing a smoother development experience.

Testing

New tests have been added to ensure that both readonly and plain string arrays are handled correctly. Note that tests don't seem to fail even when the typescript changes haven't been implemented, but there is a type error in the test in VS Code that goes away once this is implemented.

CleanShot 2023-08-09 at 15 05 05@2x
coolsoftwaretyler commented 10 months ago

Hey @jamonholmgren - this looks good to me and makes sense! I'm gonna merge it and include in the second RC for 5.2.0.