From 9ef755838b57401a6003501b2bd681d6615d55c2 Mon Sep 17 00:00:00 2001 From: Ritik Bheda Date: Thu, 16 Dec 2021 23:05:26 -0500 Subject: [PATCH 1/3] add isEqualType --- source/index.ts | 1 + source/is-equal.ts | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 source/is-equal.ts diff --git a/source/index.ts b/source/index.ts index 73bdb08..a20f2b0 100644 --- a/source/index.ts +++ b/source/index.ts @@ -6,3 +6,4 @@ export {arrayIncludes} from './array-includes.js'; export {objectKeys} from './object-keys.js'; export {objectEntries} from './object-entries.js'; export {objectHasOwn} from './object-has-own.js'; +export {isEqualType} from './is-equal.js'; diff --git a/source/is-equal.ts b/source/is-equal.ts new file mode 100644 index 0000000..48823f6 --- /dev/null +++ b/source/is-equal.ts @@ -0,0 +1,24 @@ +/** + +@example +``` +import {isEqualType} from 'ts-extras'; + +const isEqual = isEqualType(); +``` + +*/ +export type IsEqual = + (() => T extends ExpectedType ? 1 : 2) extends + (() => T extends ActualType ? 1 : 2) + ? true + : false; + +function assertType() { +} + +export function isEqualType(): boolean; +export function isEqualType(value : G): boolean; +export function isEqualType(a: T, b: G){ + return assertType, true>>(); +} \ No newline at end of file From 6263dae7e8809c69165d2f02b0ff333d02f6f862 Mon Sep 17 00:00:00 2001 From: Ritik Bheda Date: Thu, 16 Dec 2021 23:05:41 -0500 Subject: [PATCH 2/3] add tests --- test/is-equal.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test/is-equal.ts diff --git a/test/is-equal.ts b/test/is-equal.ts new file mode 100644 index 0000000..8073738 --- /dev/null +++ b/test/is-equal.ts @@ -0,0 +1,16 @@ +import test from 'ava'; +import {isEqualType} from '../source/index.js'; + +test('isEqual()', t => { + + t.true(isEqualType<1, 1>()); + t.true(isEqualType()); + t.true(isEqualType()); + + t.false(isEqualType<{}, {x:1}>()); + t.false(isEqualType<1, 2>()); + t.false(isEqualType<1, any>()); + t.false(isEqualType<1, unknown>()); + t.false(isEqualType()); + +}); From 31f882e48fac458c61a98b9e69e6d9530daf45d3 Mon Sep 17 00:00:00 2001 From: Ritik Bheda Date: Thu, 16 Dec 2021 23:08:56 -0500 Subject: [PATCH 3/3] update readme --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index 14cbcab..6810171 100644 --- a/readme.md +++ b/readme.md @@ -30,6 +30,7 @@ import {isDefined} from 'ts-extras'; - [`isDefined`](source/is-defined.ts) - Check whether a value is defined (not `null` or `undefined`). - [`isEmpty`](source/is-empty.ts) - Check whether an array is empty. - [`assertError`](source/assert-error.ts) - Assert that the given value is an `Error`. +- [`isEqualType`](source/is-equal.ts) - Check whether two types are equal. **Improved builtin**