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

Simplifies typings on just-compare #480

Merged
merged 2 commits into from
Aug 7, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions packages/collection-compare/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
// Definitions by: Justy Robles <https://github.com/justyrobles>

type Primitive = boolean | string | number | bigint | null | undefined;

declare function compare<T extends Primitive>(value1: T, value2: T): boolean;

declare function compare<T1 extends object, T2 extends object & T1>(
value1: T1,
value2: T2
): boolean;

declare function compare<T1 extends object & T2, T2 extends object>(
value1: T1,
value2: T2
): boolean;
declare function compare(value1: unknown, value2: unknown): boolean;

export default compare;
24 changes: 0 additions & 24 deletions packages/collection-compare/index.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,3 @@ const compareIt = <T extends object>(a: T, b: T) => compare(a, b);
// Not okay
// @ts-expect-error
compare();
// @ts-expect-error
compare(1, "1");
// @ts-expect-error
compare(["abc"], "abc");
// @ts-expect-error
compare({ a: 1, b: 2 }, [{ a: 1, b: 2 }]);
// @ts-expect-error
compare(obj2, obj1);
// @ts-expect-error
compare(obj1, obj2);
// @ts-expect-error
compare(obj1, num1);
// @ts-expect-error
compare(num1, obj1);
// @ts-expect-error
compare(NaN, "abc");
// @ts-expect-error
compare(funcA, funcB);
// @ts-expect-error
compare(funcA, true);
// @ts-expect-error
compare(num1, num2);
// @ts-expect-error
compare(num2, num1);