diff --git a/README.md b/README.md index 77e655c..70bcec8 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,13 @@ expectTypeOf(1).not.toBeUndefined() expectTypeOf(1).not.toBeNullable() ``` +Detect assignability of unioned types: + +```typescript +expectTypeOf().toMatchTypeOf() +expectTypeOf().not.toMatchTypeOf() +``` + Use `.extract` and `.exclude` to narrow down complex union types: ```typescript diff --git a/src/index.ts b/src/index.ts index 85a0b68..b283f44 100644 --- a/src/index.ts +++ b/src/index.ts @@ -80,7 +80,7 @@ type ReadonlyEquivalent = Extends< (() => T extends Y ? true : false) > -export type Extends = IsNever extends true ? IsNever : L extends R ? true : false +export type Extends = IsNever extends true ? IsNever : [L] extends [R] ? true : false export type StrictExtends = Extends, DeepBrand> export type Equal = And<[StrictExtends, StrictExtends]> diff --git a/test/index.test.ts b/test/index.test.ts index 02b3c01..95479a9 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -101,6 +101,11 @@ test('More `.not` examples', () => { expectTypeOf(1).not.toBeNullable() }) +test('Detect assignability of unioned types', () => { + expectTypeOf().toMatchTypeOf() + expectTypeOf().not.toMatchTypeOf() +}) + test('Use `.extract` and `.exclude` to narrow down complex union types', () => { type ResponsiveProp = T | T[] | {xs?: T; sm?: T; md?: T} const getResponsiveProp = (_props: T): ResponsiveProp => ({})