> For the complete documentation index, see [llms.txt](https://docs.tsafe.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tsafe.dev/equals.md).

# Equals

Let you test if two types are the same

### Type level  testing

<figure><img src="https://2070518381-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_DPR4G1FRgI3DwBvcp%2Fuploads%2FD3i9ewumENPykM2MXs23%2Fimage.png?alt=media&amp;token=817e7d65-fbb5-4818-a8f7-561ba8594160" alt=""><figcaption></figcaption></figure>

[Playground](https://stackblitz.com/edit/typescript-rfpzav?file=index.ts\&view=editor)

A less trivial example: [The code](https://github.com/codegouvfr/react-dsfr/blob/main/src/lib/spacing.ts) and it's [corresponding test file](https://github.com/codegouvfr/react-dsfr/blob/main/test/types/spacing.ts).

{% hint style="info" %}
If you are writing tests for your type, you definitely want to checkout [`//@ts-expect-error`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html#-ts-expect-error-comments)
{% endhint %}

### Making sure that a zod schema validates a given type

<figure><img src="https://2070518381-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_DPR4G1FRgI3DwBvcp%2Fuploads%2FhPqmAyTHNZzV5VHQMUAR%2Ftsafe-zod.gif?alt=media&amp;token=eff43e77-d250-4238-8795-e01819ef2926" alt=""><figcaption></figcaption></figure>

[Playground](https://stackblitz.com/edit/typescript-eheop6?file=index.ts\&view=editor)

```typescript

import { z } from "zod";
import { assert, type Equals } from "tsafe/assert";
import { id } from "tsafe/id";

type Xyz= // ...

const zXyz = (()=>{

   type TargetType = Xyz;
   
   const zTargetType = z.;
   
   type InferredType = z.infer<typeof zTargetType>;
   
   assert<Equals<TargetType, InferredType>>;
   
   return id<z.ZodType<TargetType>>(zTargetType);   

})();
```

### Making sure all cases of a switch are dealt with

<figure><img src="https://2070518381-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_DPR4G1FRgI3DwBvcp%2Fuploads%2FlDP3nm0eSAz2TPxZi7vP%2Fasser-equals-switch.gif?alt=media&amp;token=8fae2694-a0c4-4b01-8c19-7f840163361a" alt=""><figcaption></figcaption></figure>

[Playground](https://stackblitz.com/edit/typescript-ryj2ba?file=index.ts\&view=editor)
