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** 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 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()); + +});