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

Adding isNonEmptyArray #309

Merged
merged 2 commits into from
Aug 28, 2024
Merged

Conversation

CarlosGamero
Copy link
Collaborator

@CarlosGamero CarlosGamero commented Aug 28, 2024

Changes

Adding isNonEmptyArray method to facilitate working with nonempty constraint from Zod

Checklist

  • Apply one of following labels; major, minor, patch or skip-release
  • I've updated the documentation, or no changes were necessary
  • I've updated the tests, or no changes were necessary

@CarlosGamero CarlosGamero self-assigned this Aug 28, 2024
@CarlosGamero CarlosGamero marked this pull request as ready for review August 28, 2024 08:50
* @param {readonly T[]} array - The array to be checked, which should be read-only.
* @returns {array is [T, ...T[]]} - Returns true if the array is non-empty, false otherwise.
*/
export const isNonEmptyArray = <T>(array: readonly T[]): array is [T, ...T[]] => array.length > 0
Copy link
Collaborator

Choose a reason for hiding this comment

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

is it correct to transform readonly array into non-readonly array here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Mmm, good point! also, readonly does not make too much sense for this method (we are just checking length) removing it

@CarlosGamero CarlosGamero merged commit ebd331f into main Aug 28, 2024
4 checks passed
@CarlosGamero CarlosGamero deleted the feature/universal-ts_isNonEmptyArray branch August 28, 2024 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants