Fixes type InvertPatternForExcludeInternal to work with readonly array#284
Merged
gvergnaud merged 6 commits intogvergnaud:mainfrom Sep 23, 2024
Merged
Conversation
gvergnaud
reviewed
Sep 22, 2024
src/types/InvertPattern.ts
Outdated
Comment on lines
+321
to
+323
| ? i extends any[] | ||
| ? InvertPatternForExcludeInternal<subpattern, ii, empty>[] | ||
| : readonly InvertPatternForExcludeInternal<subpattern, ii, empty>[] |
Owner
There was a problem hiding this comment.
Stylistic: There's a pattern of using MaybeAddReadonly<T> in this file that I think we should keep:
Suggested change
| ? i extends any[] | |
| ? InvertPatternForExcludeInternal<subpattern, ii, empty>[] | |
| : readonly InvertPatternForExcludeInternal<subpattern, ii, empty>[] | |
| ? MaybeAddReadonly< | |
| InvertPatternForExcludeInternal<subpattern, ii, empty>[], | |
| IsReadonlyArray<i> | |
| > |
Contributor
Author
There was a problem hiding this comment.
@gvergnaud
it looks good! Included it in this commit 979b358
tests/lists.test.ts
Outdated
Comment on lines
+62
to
+71
| it('issue #271: P.array should support readonly arrays as its input', () => { | ||
| type Input = string | Date | readonly string[]; | ||
| const input = ['a', 'b', 'c'] as Input; | ||
|
|
||
| const output = match(input) | ||
| .with(P.array(P.string), (value) => 2) | ||
| .with(P.string, (value) => 1) | ||
| .with(P.instanceOf(Date), (value) => 3) | ||
| .exhaustive(); | ||
| }); |
Owner
There was a problem hiding this comment.
Could you move this unit test to the exhaustive-match.test.ts file?
I think this is technically a bug of exhaustiveness checking, since the problem is that without this change, the match expression isn't considered exhaustive.
Contributor
Author
There was a problem hiding this comment.
@gvergnaud Sure! I moved it in this commit 980e4d0
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.
This PR resolves the issue #271
Fixed the issue by modifying
InvertPatternForExcludeInternalto considerreadonly.