Decompose monolithic readme into docs/ directory structure
This commit is contained in:
35
docs/types/modules.md
Normal file
35
docs/types/modules.md
Normal file
@@ -0,0 +1,35 @@
|
||||
[Overview](../overview.md) | [Installation](../installation.md) | [Usage](../usage.md) | **Types** | [Values](../values/) | [Syntax](../syntax/) | [TypeRegistry](../type-registry.md) | [TypeCheck](../type-check.md)
|
||||
|
||||
# Module Types
|
||||
|
||||
Module types are containers for a set of referential types. Modules act as namespaces, enabling types to reference one another via string identifiers. Modules support both singular and mutually recursive references, as well as deferred dereferencing for computed types such as Partial. Types imported from a module are expressed using the Json Schema `$defs` keyword.
|
||||
|
||||
```typescript
|
||||
const Module = Type.Module({
|
||||
PartialUser: Type.Partial(Type.Ref("User")), // TComputed<'Partial', [TRef<'User'>]>
|
||||
|
||||
User: Type.Object({
|
||||
// TObject<{
|
||||
id: Type.String(), // user: TString,
|
||||
name: Type.String(), // name: TString,
|
||||
email: Type.String(), // email: TString
|
||||
}), // }>
|
||||
});
|
||||
const User = Module.Import("User"); // const User: TImport<{...}, 'User'>
|
||||
|
||||
type User = Static<typeof User>; // type User = {
|
||||
// id: string,
|
||||
// name: string,
|
||||
// email: string
|
||||
// }
|
||||
|
||||
const PartialUser = Module.Import("PartialUser"); // const PartialUser: TImport<{...}, 'PartialUser'>
|
||||
|
||||
type PartialUser = Static<typeof PartialUser>; // type PartialUser = {
|
||||
// id?: string,
|
||||
// name?: string,
|
||||
// email?: string
|
||||
// }
|
||||
```
|
||||
|
||||
Back to [Home](../../readme.md)
|
||||
Reference in New Issue
Block a user