-
-
Notifications
You must be signed in to change notification settings - Fork 135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes type InvertPatternForExcludeInternal
to work with readonly array
#284
Fixes type InvertPatternForExcludeInternal
to work with readonly array
#284
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great investigation! a few minor comments but otherwise it looks good to me. Thank you for contributing! 🎉
src/types/InvertPattern.ts
Outdated
? i extends any[] | ||
? InvertPatternForExcludeInternal<subpattern, ii, empty>[] | ||
: readonly InvertPatternForExcludeInternal<subpattern, ii, empty>[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stylistic: There's a pattern of using MaybeAddReadonly<T>
in this file that I think we should keep:
? i extends any[] | |
? InvertPatternForExcludeInternal<subpattern, ii, empty>[] | |
: readonly InvertPatternForExcludeInternal<subpattern, ii, empty>[] | |
? MaybeAddReadonly< | |
InvertPatternForExcludeInternal<subpattern, ii, empty>[], | |
IsReadonlyArray<i> | |
> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gvergnaud
it looks good! Included it in this commit 979b358
tests/lists.test.ts
Outdated
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(); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gvergnaud Sure! I moved it in this commit 980e4d0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
This PR resolves the issue #271
Fixed the issue by modifying
InvertPatternForExcludeInternal
to considerreadonly
.