Skip to content

Commit

Permalink
Handle readonly arrays for isNonEmptyArray guard. (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebennett88 committed Mar 22, 2023
1 parent bbe5d72 commit 3b73321
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/olive-dryers-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'emery': patch
---

Handle readonly arrays for `isNonEmptyArray` guard.
2 changes: 2 additions & 0 deletions src/guards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ describe('guards', () => {
describe('array', () => {
it('isNonEmptyArray should validate assumed values', () => {
expect(isNonEmptyArray([1, 2])).toBe(true);
expect(isNonEmptyArray([1, 2] as const)).toBe(true);
expect(isNonEmptyArray([])).toBe(false);
expect(isNonEmptyArray([] as const)).toBe(false);
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/guards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function isUndefined(value: unknown): value is undefined {
// ------------------------------

/** Checks whether or not an array is empty. */
export function isNonEmptyArray<T>(value: T[]): value is [T, ...T[]] {
export function isNonEmptyArray<T>(value: readonly T[]): value is [T, ...T[]] {
return value.length > 0;
}

Expand Down

1 comment on commit 3b73321

@vercel
Copy link

@vercel vercel bot commented on 3b73321 Mar 22, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

emery – ./

emery-thinkmill.vercel.app
emery-ts.vercel.app
emery-git-main-thinkmill.vercel.app

Please sign in to comment.