Skip to content
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

Merged
merged 6 commits into from
Sep 23, 2024

Conversation

changwoolab
Copy link
Contributor

This PR resolves the issue #271

Fixed the issue by modifying InvertPatternForExcludeInternal to consider readonly .

Copy link
Owner

@gvergnaud gvergnaud left a 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! 🎉

Comment on lines 321 to 323
? i extends any[]
? InvertPatternForExcludeInternal<subpattern, ii, empty>[]
: readonly InvertPatternForExcludeInternal<subpattern, ii, empty>[]
Copy link
Owner

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:

Suggested change
? i extends any[]
? InvertPatternForExcludeInternal<subpattern, ii, empty>[]
: readonly InvertPatternForExcludeInternal<subpattern, ii, empty>[]
? MaybeAddReadonly<
InvertPatternForExcludeInternal<subpattern, ii, empty>[],
IsReadonlyArray<i>
>

Copy link
Contributor Author

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

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();
});
Copy link
Owner

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.

Copy link
Contributor Author

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

Copy link
Owner

@gvergnaud gvergnaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

tests/exhaustive-match.test.ts Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants