Decompose monolithic readme into docs/ directory structure
This commit is contained in:
41
docs/types/indexed.md
Normal file
41
docs/types/indexed.md
Normal file
@@ -0,0 +1,41 @@
|
||||
[Overview](../overview.md) | [Installation](../installation.md) | [Usage](../usage.md) | **Types** | [Values](../values/) | [Syntax](../syntax/) | [TypeRegistry](../type-registry.md) | [TypeCheck](../type-check.md)
|
||||
|
||||
# Indexed Access Types
|
||||
|
||||
TypeBox supports indexed access types with the Index function. This function enables uniform access to interior property and element types without having to extract them from the underlying schema representation. Index types are supported for Object, Array, Tuple, Union and Intersect types.
|
||||
|
||||
```typescript
|
||||
const T = Type.Object({
|
||||
// type T = {
|
||||
x: Type.Number(), // x: number,
|
||||
y: Type.String(), // y: string,
|
||||
z: Type.Boolean(), // z: boolean
|
||||
}); // }
|
||||
|
||||
const A = Type.Index(T, ["x"]); // type A = T['x']
|
||||
//
|
||||
// ... evaluated as
|
||||
//
|
||||
// const A: TNumber
|
||||
|
||||
const B = Type.Index(T, ["x", "y"]); // type B = T['x' | 'y']
|
||||
//
|
||||
// ... evaluated as
|
||||
//
|
||||
// const B: TUnion<[
|
||||
// TNumber,
|
||||
// TString,
|
||||
// ]>
|
||||
|
||||
const C = Type.Index(T, Type.KeyOf(T)); // type C = T[keyof T]
|
||||
//
|
||||
// ... evaluated as
|
||||
//
|
||||
// const C: TUnion<[
|
||||
// TNumber,
|
||||
// TString,
|
||||
// TBoolean
|
||||
// ]>
|
||||
```
|
||||
|
||||
Back to [Home](../../readme.md)
|
||||
Reference in New Issue
Block a user