Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix is-empty return type #552

Merged
merged 1 commit into from
May 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions packages/object-is-empty/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
type ReturnTrueValues = null | undefined | "" | [] | number | boolean | Symbol;
type ReturnFalseValues = string | any[];
type CheckValue = ReturnTrueValues | ReturnFalseValues | object;
type CheckValue = ReturnTrueValues | object | string | any[];

declare function isEmpty<T extends CheckValue>(
obj: T
): T extends ReturnTrueValues
? true
: T extends ReturnFalseValues
? false
: boolean;

export default isEmpty;
18 changes: 9 additions & 9 deletions packages/object-is-empty/index.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ import isEmpty from "./index";
const test1: true = isEmpty(null);
const test2: true = isEmpty(undefined);
const test3: true = isEmpty([]);
const test4: false = isEmpty([1, 2]);
const test5: false = isEmpty("abc");
const test6: true = isEmpty("");
const test7: true = isEmpty(0);
const test8: true = isEmpty(1);
const test9: true = isEmpty(true);
const test10: true = isEmpty(false);
const test11: true = isEmpty(Symbol("abc"));
const test12: true = isEmpty(Symbol(""));
const test4: true = isEmpty("");
const test5: true = isEmpty(0);
const test6: true = isEmpty(1);
const test7: true = isEmpty(true);
const test8: true = isEmpty(false);
const test9: true = isEmpty(Symbol("abc"));
const test10: true = isEmpty(Symbol(""));

// Unknown
const test11: boolean = isEmpty([1, 2]);
const test12: boolean = isEmpty("abc");
const test13: boolean = isEmpty({ a: 3, b: 5 });
const test14: boolean = isEmpty(new Set([1, 2, 2]));
const test15: boolean = isEmpty(new Map().set("a", 2));
Expand Down