Merged
Conversation
42cd002 to
c91a019
Compare
|
Thanks for looking into this! |
7a21325 to
3427654
Compare
som-sm
commented
May 1, 2025
|
|
||
| // === Arrays === | ||
| expectType<[string, number | null, boolean]>({} as SetNonNullableDeep<[string | null, number | null, boolean | undefined], '0' | '2'>); | ||
| expectType<{a?: [string, number, (boolean | null)?] | null}>({} as SetNonNullableDeep<{a?: [string | undefined, number | undefined, (boolean | null)?] | null}, 'a.0' | 'a.1'>); |
Collaborator
Author
There was a problem hiding this comment.
Something really strange is happening here. If I remove the test on line 106, some tests in set-required-deep.ts start failing—tests that are completely unrelated to this. And there's no changes in SetRequiredDeep related files.
And this doesn't just fail locally, it also fails in CI.
@sindresorhus @Emiyaaaaa Do you have any idea why this could be happening?
weird-compressed.mov
Owner
There was a problem hiding this comment.
No idea. Probably some compiler quirk.
The minimum. Any more simplifications of this and it triggers the issue.
expectType<{a?: [string]}>({} as SetNonNullableDeep<{a?: [string]}, 'a.0'>);3427654 to
8a52c78
Compare
Owner
|
Looks good 👍 |
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.
Closes #795
Notes:
Currently, there’s no way to remove nullables just from the rest element in an array type. For instance, you can’t get
[string | null, …number[]]from[string | null, …(number | null)[]].Furthermore, it’s not very obvious what
KeyPathsshould be used to target the rest element. Usingnumberwould target all elements, not just the rest element (refer to the next point).Rest elements in array types behave slightly differently across versions when
KeyPathsincludesnumber. Refer the example below:SetNonNullableDeepcurrently doesn't deeply remove all nullables ifKeyPathsisany. This will require a separateNonNullableDeeptype, which I'll create it a separate PR.