forked from orbit-oss/is
Fix type narrowing for nonEmptyArray (#185)
This commit is contained in:
parent
9265e9072d
commit
3177d11801
2 changed files with 61 additions and 12 deletions
67
test/test.ts
67
test/test.ts
|
|
@ -1448,16 +1448,65 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const strings = ['🦄', 'unicorn'];
|
||||
const function_ = (value: string) => value;
|
||||
|
||||
assert.nonEmptyArray(strings);
|
||||
|
||||
const value = strings[0];
|
||||
function_(value);
|
||||
}
|
||||
|
||||
{
|
||||
const mixed = ['🦄', 'unicorn', 1, 2];
|
||||
const function_ = (value: string | number) => value;
|
||||
|
||||
assert.nonEmptyArray(mixed);
|
||||
|
||||
const value = mixed[0];
|
||||
function_(value);
|
||||
}
|
||||
|
||||
{
|
||||
const arrays = [['🦄'], ['unicorn']];
|
||||
const function_ = (value: string[]) => value;
|
||||
|
||||
assert.nonEmptyArray(arrays);
|
||||
|
||||
const value = arrays[0];
|
||||
function_(value);
|
||||
}
|
||||
});
|
||||
|
||||
test('is.emptyString', t => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue