Decompose monolithic readme into docs/ directory structure

This commit is contained in:
2026-04-23 13:57:56 +00:00
parent 560bb00433
commit f8b2cdd5a4
47 changed files with 1936 additions and 1829 deletions

42
docs/types/conditional.md Normal file
View File

@@ -0,0 +1,42 @@
[Overview](../overview.md) | [Installation](../installation.md) | [Usage](../usage.md) | **Types** | [Values](../values/) | [Syntax](../syntax/) | [TypeRegistry](../type-registry.md) | [TypeCheck](../type-check.md)
# Conditional Types
TypeBox supports runtime conditional types with the Extends function. This function performs a structural assignability check against the first (`left`) and second (`right`) arguments and will return either the third (`true`) or fourth (`false`) argument based on the result. The conditional types Exclude and Extract are also supported. The following shows both TypeScript and TypeBox examples of conditional types.
```typescript
// Extends
const A = Type.Extends(
// type A = string extends number ? 1 : 2
Type.String(), //
Type.Number(), // ... evaluated as
Type.Literal(1), //
Type.Literal(2) // const A: TLiteral<2>
);
// Extract
const B = Type.Extract(
// type B = Extract<1 | 2 | 3, 1>
Type.Union([
//
Type.Literal(1), // ... evaluated as
Type.Literal(2), //
Type.Literal(3), // const B: TLiteral<1>
]),
Type.Literal(1)
);
// Exclude
const C = Type.Exclude(
// type C = Exclude<1 | 2 | 3, 1>
Type.Union([
//
Type.Literal(1), // ... evaluated as
Type.Literal(2), //
Type.Literal(3), // const C: TUnion<[
]), // TLiteral<2>,
Type.Literal(1) // TLiteral<3>,
); // ]>
```
Back to [Home](../../readme.md)