From ebb32b156755bee0b7f6efe25fcf22bce524fb70 Mon Sep 17 00:00:00 2001 From: Luke Bennett Date: Fri, 19 Aug 2022 13:24:12 +1000 Subject: [PATCH] Handle readonly arrays for `isNonEmptyArray` guard. --- .changeset/olive-dryers-destroy.md | 5 +++++ src/guards.test.ts | 2 ++ src/guards.ts | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changeset/olive-dryers-destroy.md diff --git a/.changeset/olive-dryers-destroy.md b/.changeset/olive-dryers-destroy.md new file mode 100644 index 0000000..cc31eaf --- /dev/null +++ b/.changeset/olive-dryers-destroy.md @@ -0,0 +1,5 @@ +--- +'emery': patch +--- + +Handle readonly arrays for `isNonEmptyArray` guard. diff --git a/src/guards.test.ts b/src/guards.test.ts index 246ab9a..e2ab57a 100644 --- a/src/guards.test.ts +++ b/src/guards.test.ts @@ -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); }); }); diff --git a/src/guards.ts b/src/guards.ts index 20784ef..257a0e9 100644 --- a/src/guards.ts +++ b/src/guards.ts @@ -33,7 +33,7 @@ export function isUndefined(value: unknown): value is undefined { // ------------------------------ /** Checks whether or not an array is empty. */ -export function isNonEmptyArray(value: T[]): value is [T, ...T[]] { +export function isNonEmptyArray(value: readonly T[]): value is [T, ...T[]] { return value.length > 0; }