fix(isNotNil): simplify isNotNil and add testcases (#519)

* Simplify isNotNil and add testcases

* fix chore
This commit is contained in:
Dayong Lee 2024-09-13 08:51:30 +09:00 committed by GitHub
parent 3409d25a8d
commit 7258981909
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 2 deletions

View File

@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest';
import { isBoolean } from './isBoolean';
describe('isNull', () => {
describe('isBoolean', () => {
it('returns true if the value is boolean', () => {
expect(isBoolean(true)).toBe(true);
expect(isBoolean(false)).toBe(true);

View File

@ -10,6 +10,10 @@ describe('isNotNil', () => {
it('returns true if the value is not null nor undefined', () => {
expect(isNotNil('')).toBe(true);
expect(isNotNil(123)).toBe(true);
expect(isNotNil(0)).toBe(true);
expect(isNotNil(false)).toBe(true);
expect(isNotNil(true)).toBe(true);
expect(isNotNil([])).toBe(true);
});
it('can be used with TypeScript as a type predicate', () => {

View File

@ -15,5 +15,5 @@
* // result will be [1, 3]
*/
export function isNotNil<T>(x: T | null | undefined): x is T {
return x !== null && x !== undefined;
return x != null;
}