WritableKeysOf / ReadonlyKeysOf: Fix behaviour with unions and optional properties#1088
Merged
sindresorhus merged 7 commits intomainfrom Mar 27, 2025
Merged
Conversation
d8ee0ec to
2443b48
Compare
2443b48 to
0587ca9
Compare
WritableKeysOf: Fix behaviour with optional propertiesWritableKeysOf / ReadonlyKeysOf: Fix behaviour with unions and optional properties
Collaborator
Author
I had to do a similar thing in |
Collaborator
Author
|
Also, @sindresorhus in type-fest/source/optional-keys-of.d.ts Line 34 in a6590b9 |
Owner
Agreed. Added to the list. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1087
Looks like there's some issue in TS
v5.4and later, because it works fine inv5.3and below (playground link). Regardless, the updated implementation should work fine across all versions.Also, fixes behaviour with unions.
The updated implementation also improves behaviour with arrays:
However, I had to comment out the array cases because looks like there's some issue with
readonlyarrays inv5.1andv5.2.In
v5.1andv5.2, thenumberkey loses it'sreadonlymodifier while mapping, causingWritableKeys<readonly [string]>to incorrectly includenumberin its result.In
v5.3and higher, thenumberkey correctly preserves it'sreadonlymodifier while mapping, soWritableKeys<readonly [string]>no longer hasnumberin it's result.We'll probably have to figure out a way in which we can run certain test cases only for certain specific versions.