diff --git a/.changeset/heavy-feet-sin.md b/.changeset/heavy-feet-sin.md new file mode 100644 index 0000000..e283cae --- /dev/null +++ b/.changeset/heavy-feet-sin.md @@ -0,0 +1,5 @@ +--- +"@crbroughton/ts-test-utils": minor +--- + +Add the Extends type - Check if one type extends from another diff --git a/index.ts b/index.ts index 055c82b..055b113 100644 --- a/index.ts +++ b/index.ts @@ -7,3 +7,5 @@ export type Includes = T extends U ? true : false export type Excludes = [T] extends [U] ? false : true export type Assignable = U extends T ? true : false + +export type Extends = U extends T ? true : false diff --git a/tests/Extends.test.ts b/tests/Extends.test.ts new file mode 100644 index 0000000..18fa93e --- /dev/null +++ b/tests/Extends.test.ts @@ -0,0 +1,20 @@ +/* eslint-disable unused-imports/no-unused-vars */ +import { describe, it } from 'bun:test' +import type { Expect, Extends } from '..' + +describe('Extends tests', () => { + it('Passes the extend test when the resulting type extends another type', () => { + interface BaseType { id: number } + type ExtensionType = BaseType & { name: string } + type Result = Expect> + // ^? + }) + it('Failed the includes test when the resulting type does not include the sub-type', () => { + // @ts-expect-error - Object / Record failing the equality checker + type Result = Expect> + // ^? + }) +}) + + +