diff --git a/packages/collection-compare/index.d.ts b/packages/collection-compare/index.d.ts index 670252286..f6218bdda 100644 --- a/packages/collection-compare/index.d.ts +++ b/packages/collection-compare/index.d.ts @@ -4,14 +4,14 @@ type Primitive = boolean | string | number | bigint | null | undefined; declare function compare(value1: T, value2: T): boolean; -declare function compare( - value1: Exclude, - value2: Exclude +declare function compare( + value1: T1, + value2: T2 ): boolean; -declare function compare( - value1: Exclude, - value2: Exclude +declare function compare( + value1: T1, + value2: T2 ): boolean; export default compare; diff --git a/packages/collection-compare/index.tests.ts b/packages/collection-compare/index.tests.ts index 340cdd517..8198c403c 100644 --- a/packages/collection-compare/index.tests.ts +++ b/packages/collection-compare/index.tests.ts @@ -45,6 +45,7 @@ compare(obj1, { b: 3, a: 2 }); compare([1, [2, { a: 4 }], 4], [1, [2, { a: 4 }]]); compare([1, [2, { a: 4 }], 4], [1, [2, { a: 4 }], 4]); compare(NaN, NaN); +const compareIt = (a: T, b: T) => compare(a, b); // Not okay // @ts-expect-error @@ -60,6 +61,10 @@ 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); diff --git a/packages/collection-compare/package.json b/packages/collection-compare/package.json index 96bf6779c..75b8d3173 100644 --- a/packages/collection-compare/package.json +++ b/packages/collection-compare/package.json @@ -6,6 +6,7 @@ "module": "index.mjs", "exports": { ".": { + "types": "./index.d.ts", "require": "./index.js", "default": "./index.mjs" }