Skip to content

Commit

Permalink
Address pull request comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ifiokjr committed Nov 1, 2021
1 parent 2f8189a commit 77df06b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
4 changes: 2 additions & 2 deletions source/array-includes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
A better version `Array.prototype.includes` which allows other types to be included and also acts as a type guard when the provided array is of a specific type.
An alternative to `Array.prototype.includes` but acting as a type guard
This is needed because `Array.prototype.includes` doesn't allow for other types to be included.
The proposal was rejected in this issue: https://github.com/microsoft/TypeScript/issues/26255#issuecomment-748211891
@example
```
Expand Down
10 changes: 3 additions & 7 deletions test/array-includes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,16 @@ test('arrayIncludes()', t => {
const invalidValue: unknown = 'd';
let testValueType: typeof values[number];

t.is(arrayIncludes(values, validValue), true);
t.is(arrayIncludes(values, invalidValue), false);
t.true(arrayIncludes(values, validValue));
t.false(arrayIncludes(values, invalidValue));

// eslint-disable-next-line unicorn/prefer-ternary
if (arrayIncludes(values, validValue)) {
testValueType = validValue;
} else {
doNothing(); // Removes the `unicorn/prefer-ternary` failure;
// @ts-expect-error
testValueType = validValue;
}

t.is(testValueType, 'a');
});

function doNothing() {
// Do nothing
}

0 comments on commit 77df06b

Please sign in to comment.