Skip to content

Commit

Permalink
Fix is.nonEmptyArray() type narrowing with undefined (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene-mohc authored Jul 17, 2023
1 parent ad0c3b1 commit 20ad823
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ is.oddInteger = isAbsoluteMod2(1);

is.emptyArray = (value: unknown): value is never[] => is.array(value) && value.length === 0;

is.nonEmptyArray = <T = unknown, Item = unknown>(value: T | Item[]): value is (T extends Item[] ? [Item, ...Item[]] : T) => is.array(value) && value.length > 0;
is.nonEmptyArray = <T = unknown, Item = unknown>(value: T | Item[]): value is [Item, ...Item[]] => is.array(value) && value.length > 0;

is.emptyString = (value: unknown): value is '' => is.string(value) && value.length === 0;

Expand Down Expand Up @@ -584,7 +584,7 @@ type Assert = {
nodeStream: (value: unknown) => asserts value is NodeStream;
infinite: (value: unknown) => asserts value is number;
emptyArray: (value: unknown) => asserts value is never[];
nonEmptyArray: <T = unknown, Item = unknown>(value: T | Item[]) => asserts value is (T extends Item[] ? [Item, ...Item[]] : T);
nonEmptyArray: <T = unknown, Item = unknown>(value: T | Item[]) => asserts value is [Item, ...Item[]];
emptyString: (value: unknown) => asserts value is '';
emptyStringOrWhitespace: (value: unknown) => asserts value is string;
nonEmptyString: (value: unknown) => asserts value is string;
Expand Down Expand Up @@ -692,7 +692,7 @@ export const assert: Assert = {
nodeStream: (value: unknown): asserts value is NodeStream => assertType(is.nodeStream(value), AssertionTypeDescription.nodeStream, value),
infinite: (value: unknown): asserts value is number => assertType(is.infinite(value), AssertionTypeDescription.infinite, value),
emptyArray: (value: unknown): asserts value is never[] => assertType(is.emptyArray(value), AssertionTypeDescription.emptyArray, value),
nonEmptyArray: <T = unknown, Item = unknown>(value: T | Item[]): asserts value is (T extends Item[] ? [Item, ...Item[]] : T) => assertType(is.nonEmptyArray(value), AssertionTypeDescription.nonEmptyArray, value),
nonEmptyArray: <T = unknown, Item = unknown>(value: T | Item[]): asserts value is [Item, ...Item[]] => assertType(is.nonEmptyArray(value), AssertionTypeDescription.nonEmptyArray, value),
emptyString: (value: unknown): asserts value is '' => assertType(is.emptyString(value), AssertionTypeDescription.emptyString, value),
emptyStringOrWhitespace: (value: unknown): asserts value is string => assertType(is.emptyStringOrWhitespace(value), AssertionTypeDescription.emptyStringOrWhitespace, value),
nonEmptyString: (value: unknown): asserts value is string => assertType(is.nonEmptyString(value), AssertionTypeDescription.nonEmptyString, value),
Expand Down
4 changes: 2 additions & 2 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1626,7 +1626,7 @@ test('is.nonEmptyArray', t => {
});

{
const strings = ['🦄', 'unicorn'];
const strings = ['🦄', 'unicorn'] as string[] | undefined;
const function_ = (value: string) => value;

if (is.nonEmptyArray(strings)) {
Expand Down Expand Up @@ -1656,7 +1656,7 @@ test('is.nonEmptyArray', t => {
}

{
const strings = ['🦄', 'unicorn'];
const strings = ['🦄', 'unicorn'] as string[] | undefined;
const function_ = (value: string) => value;

assert.nonEmptyArray(strings);
Expand Down

0 comments on commit 20ad823

Please sign in to comment.