diff --git a/README.md b/README.md index e3cf143..7044154 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,12 @@ npm install ts-expect --save ## Usage ```ts -import { expectType, TypeOf } from "ts-expect"; +import { expectType, TypeOf, TypeEqual } from "ts-expect"; expectType(123); // Compiler error! + +expectType>(true); +expectType>(true); ``` ### Examples diff --git a/src/index.spec.ts b/src/index.spec.ts index 832d62c..49284e8 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -1,4 +1,4 @@ -import { expectType, TypeOf } from "./index"; +import { expectType, TypeOf, TypeEqual } from "./index"; describe("ts expect", () => { it("should expect types", () => { @@ -10,7 +10,29 @@ describe("ts expect", () => { const result = expectType(""); expect(result).toEqual(undefined); + }); + + describe("TypeOf", () => { + it("should support type of checks", () => { + expectType>(true); + expectType>(false); + expectType>(true); + expectType>(false); + }); + }); + + describe("TypeEqual", () => { + it("should check types are equal", () => { + expectType>(true); + expectType>(false); + expectType>(false); + expectType>(true); + + expectType>(false); + expectType>(false); - expectType>(true); + expectType>(false); + expectType>(true); + }); }); }); diff --git a/src/index.ts b/src/index.ts index b85ce51..0821e13 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,6 +3,11 @@ */ export type TypeOf = Exclude extends never ? true : false; +/** + * Checks that `T` is equal to `U`. + */ +export type TypeEqual = Exclude extends never ? Exclude extends never ? true : false : false; + /** * Assert the parameter is of a specific type. */