Skip to content

Commit

Permalink
chore: add readonly array w/ enum type assertions;
Browse files Browse the repository at this point in the history
- Closes #10
  • Loading branch information
lukeed committed Aug 31, 2024
1 parent 5bcb4ef commit 09c541e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions infer.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,44 @@ A5[0] = { name: STRING };
// items arent readonly
A5[0].name = STRING;

// ---
// ARRAY / ENUM
// ---

let a6 = t.array(
t.enum(['UP', 'DOWN', 'LEFT', 'RIGHT']),
);

type A6 = t.Infer<typeof a6>;
declare let A6: A6;

// @ts-expect-error; incomplete
assert<('UP' | 'DOWN' | 'LEFT')[]>(A6);
assert<('UP' | 'DOWN' | 'LEFT' | 'RIGHT')[]>(A6);

// @ts-expect-error; invalid
assert<A6>(['ANOTHER']);
assert<A6>(['DOWN']);
assert<A6>([]);

// ---
// ARRAY / READONLY w/ ENUM
// ---

let a7 = t.readonly(a6);

type A7 = t.Infer<typeof a7>;
declare let A7: A7;

// @ts-expect-error; incomplete
assert<readonly ('UP' | 'DOWN' | 'LEFT')[]>(A7);
assert<readonly ('UP' | 'DOWN' | 'LEFT' | 'RIGHT')[]>(A7);

// @ts-expect-error; invalid
assert<A7>(['ANOTHER']);
assert<A7>(['DOWN']);
assert<A7>([]);

// ---
// TUPLE
// ---
Expand Down

0 comments on commit 09c541e

Please sign in to comment.