Skip to content

Commit 7e382ef

Browse files
authored
docs: add documentation for branded helper (#9248)
1 parent a85203d commit 7e382ef

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

api/expect-typeof.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,3 +549,23 @@ expectTypeOf(obj).toHaveProperty('a').toBeNumber()
549549
expectTypeOf(obj).toHaveProperty('b').toBeString()
550550
expectTypeOf(obj).toHaveProperty('a').not.toBeString()
551551
```
552+
553+
## branded
554+
555+
- **Type:** `ExpectTypeOf<BrandedType>`
556+
557+
You can use `.branded` to allow type assertions to succeed for types that are semantically equivalent but differ in representation.
558+
559+
```ts
560+
import { expectTypeOf } from 'vitest'
561+
562+
// Without .branded, this fails even though the types are effectively the same
563+
expectTypeOf<{ a: { b: 1 } & { c: 1 } }>().toEqualTypeOf<{ a: { b: 1; c: 1 } }>()
564+
565+
// With .branded, the assertion succeeds
566+
expectTypeOf<{ a: { b: 1 } & { c: 1 } }>().branded.toEqualTypeOf<{ a: { b: 1; c: 1 } }>()
567+
```
568+
569+
::: warning
570+
This helper comes at a performance cost and can cause the TypeScript compiler to 'give up' if used with excessively deep types. Use it sparingly and only when necessary.
571+
:::

0 commit comments

Comments
 (0)