|
| 1 | +import { expectTypeOf } from 'expect-type'; |
| 2 | +import { DeepUnbranded, Unbranded, WithBrands } from './interfaces'; |
| 3 | + |
| 4 | +test('DeepUnbranded', () => { |
| 5 | + type BrandedString = WithBrands<string, 'BrandedString'>; |
| 6 | + expectTypeOf<DeepUnbranded<BrandedString>>().toEqualTypeOf<string>(); |
| 7 | + |
| 8 | + type BrandedObject = WithBrands<{ string: BrandedString }, 'BrandedObject'>; |
| 9 | + expectTypeOf<Unbranded<BrandedObject>>().toEqualTypeOf<{ string: BrandedString }>(); |
| 10 | + expectTypeOf<Unbranded<BrandedObject>>().not.toEqualTypeOf<{ string: string }>(); |
| 11 | + expectTypeOf<DeepUnbranded<BrandedObject>>().toEqualTypeOf<{ string: string }>(); |
| 12 | + |
| 13 | + type BrandedArray = WithBrands<BrandedObject[], 'BrandedArray'>; |
| 14 | + expectTypeOf<Unbranded<BrandedArray>>().toEqualTypeOf<BrandedObject[]>(); |
| 15 | + expectTypeOf<DeepUnbranded<BrandedArray>>().toEqualTypeOf<Array<{ string: string }>>(); |
| 16 | + |
| 17 | + type BrandedReadonlyArray = WithBrands<readonly BrandedObject[], 'BrandedReadonlyArray'>; |
| 18 | + expectTypeOf<Unbranded<BrandedReadonlyArray>>().toEqualTypeOf<readonly BrandedObject[]>(); |
| 19 | + expectTypeOf<DeepUnbranded<BrandedReadonlyArray>>().toEqualTypeOf<ReadonlyArray<{ string: string }>>(); |
| 20 | + |
| 21 | + type BrandedEmptyTuple = WithBrands<[], 'BrandedEmptyTuple'>; |
| 22 | + expectTypeOf<Unbranded<BrandedEmptyTuple>>().toEqualTypeOf<[]>(); |
| 23 | + expectTypeOf<DeepUnbranded<BrandedEmptyTuple>>().toEqualTypeOf<[]>(); |
| 24 | + |
| 25 | + type BrandedTuple = WithBrands<readonly [BrandedObject, BrandedObject, BrandedObject], 'BrandedTuple'>; |
| 26 | + expectTypeOf<Unbranded<BrandedTuple>>().toEqualTypeOf<readonly [BrandedObject, BrandedObject, BrandedObject]>(); |
| 27 | + expectTypeOf<DeepUnbranded<BrandedTuple>>().toHaveProperty('length').toEqualTypeOf<3>(); |
| 28 | + // This is the best we can do for now: (note the `toMatchTypeOf` instead of the `toEqualTypeOf`) |
| 29 | + expectTypeOf<DeepUnbranded<BrandedTuple>>().toMatchTypeOf<readonly [{ string: string }, { string: string }, { string: string }]>(); |
| 30 | + |
| 31 | + // It should be enough for most cases: |
| 32 | + [{ string: 'abc' }, { string: 'abc' }, { string: 'abc' }] satisfies DeepUnbranded<BrandedTuple>; |
| 33 | +}); |
0 commit comments