Skip to content

Commit

Permalink
fix: Troubleshooting a bug in which an empty array is deduced as an a…
Browse files Browse the repository at this point in the history
…rray of Dates unconditionally #4
  • Loading branch information
kakasoo committed Jan 26, 2025
1 parent a363ced commit 6f95218
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/types/DeepStrictUnbrand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ namespace DeepStrictUnbrand {
* type Example3 = DeepStrictUnbrand<Array<string & { __brand: 'email' }>>; // Array<string>
* ```
*/
export type DeepStrictUnbrand<T> =
T extends Array<Date>
export type DeepStrictUnbrand<T> = T extends []
? []
: T extends Array<Date>
? Array<Date>
: T extends Array<infer I extends object>
? Array<DeepStrictUnbrand<I>>
Expand Down
14 changes: 14 additions & 0 deletions test/types/DeepStrictUnbrand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ import test from 'node:test';
import typia from 'typia';
import { DeepStrictUnbrand, Equal } from '../../src';

test('If it is empty array', () => {
type Question = DeepStrictUnbrand<[]>;
type Answer = Equal<Question, []>;

ok(typia.random<Answer>());
});

test('If it is empty array', () => {
type Question = DeepStrictUnbrand<[][]>;
type Answer = Equal<Question, [][]>;

ok(typia.random<Answer>());
});

test('If it is not a brand type', () => {
type Question = DeepStrictUnbrand<string | Date>;
type Answer = Equal<Question, string | Date>;
Expand Down

0 comments on commit 6f95218

Please sign in to comment.