Decompose monolithic readme into docs/ directory structure
This commit is contained in:
20
docs/values/cast.md
Normal file
20
docs/values/cast.md
Normal file
@@ -0,0 +1,20 @@
|
||||
[Overview](../overview.md) | [Installation](../installation.md) | [Usage](../usage.md) | [Types](../types/) | **Values** | [Syntax](../syntax/) | [TypeRegistry](../type-registry.md) | [TypeCheck](../type-check.md)
|
||||
|
||||
# Cast
|
||||
|
||||
Use the Cast function to upcast a value into a target type. This function will retain as much information as possible from the original value. The Cast function is intended to be used in data migration scenarios where existing values need to be upgraded to match a modified type.
|
||||
|
||||
```typescript
|
||||
const T = Type.Object(
|
||||
{ x: Type.Number(), y: Type.Number() },
|
||||
{ additionalProperties: false }
|
||||
);
|
||||
|
||||
const X = Value.Cast(T, null); // const X = { x: 0, y: 0 }
|
||||
|
||||
const Y = Value.Cast(T, { x: 1 }); // const Y = { x: 1, y: 0 }
|
||||
|
||||
const Z = Value.Cast(T, { x: 1, y: 2, z: 3 }); // const Z = { x: 1, y: 2 }
|
||||
```
|
||||
|
||||
Back to [Home](../../readme.md)
|
||||
Reference in New Issue
Block a user