diff --git a/source/index.ts b/source/index.ts index 07528b2..e366b82 100644 --- a/source/index.ts +++ b/source/index.ts @@ -384,7 +384,7 @@ is.oddInteger = isAbsoluteMod2(1); is.emptyArray = (value: unknown): value is never[] => is.array(value) && value.length === 0; -is.nonEmptyArray = (value: unknown): value is [unknown, ...unknown[]] => is.array(value) && value.length > 0; +is.nonEmptyArray = (value: T | T[]): value is [T, ...T[]] => is.array(value) && value.length > 0; is.emptyString = (value: unknown): value is '' => is.string(value) && value.length === 0; diff --git a/test/test.ts b/test/test.ts index 11f7f9c..d72d41d 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1448,16 +1448,35 @@ test('is.nonEmptyArray', t => { assert.nonEmptyArray(new Array()); // eslint-disable-line @typescript-eslint/no-array-constructor }); - // https://github.com/sindresorhus/is/issues/174 - // { - // const strings = ['foo', 'bar'] - // const function_ = (value: string) => value; + { + const strings = ['🦄', 'unicorn']; + const function_ = (value: string) => value; - // if (is.nonEmptyArray(strings)) { - // const value = strings[0] - // function_(value); - // } - // } + if (is.nonEmptyArray(strings)) { + const value = strings[0]; + function_(value); + } + } + + { + const mixed = ['🦄', 'unicorn', 1, 2]; + const function_ = (value: string | number) => value; + + if (is.nonEmptyArray(mixed)) { + const value = mixed[0]; + function_(value); + } + } + + { + const arrays = [['🦄'], ['unicorn']]; + const function_ = (value: string[]) => value; + + if (is.nonEmptyArray(arrays)) { + const value = arrays[0]; + function_(value); + } + } }); test('is.emptyString', t => {