-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from mahabubx7/13-documentation
[Patch & Docs] Added a validator fix + documentations for guides
- Loading branch information
Showing
20 changed files
with
556 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Array | ||
|
||
::: info | ||
We are wotking on it. | ||
Work in progress ⏳ | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Boolean | ||
|
||
::: info | ||
We are wotking on it. | ||
Work in progress ⏳ | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Enum | ||
|
||
::: info | ||
We are wotking on it. | ||
Work in progress ⏳ | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Number | ||
|
||
::: info | ||
We are wotking on it. | ||
Work in progress ⏳ | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Object | ||
|
||
::: info | ||
We are wotking on it. | ||
Work in progress ⏳ | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# String | ||
|
||
::: info | ||
We are wotking on it. | ||
Work in progress ⏳ | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
# Welcome! | ||
|
||
::: info | ||
This package is almost ready for its first release `v1.0.0-beta`. | ||
It is still in `development` and very soon will be available in npm. | ||
This package is available with its latest release `v1.0.1` or later. | ||
It is still in `development` and very soon will have its first stable/lts release. | ||
::: | ||
|
||
If you consider this project useful or worth the attentions of developers, then please give its GitHub repository a star. Also, you can contribute to this open-source project. Follow the guidelines to contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Infer Types | ||
|
||
## Summary | ||
|
||
While working in TypeScript, we often need to use types for various usages. Our library gives the opportunity to generate types from your defined schemas. | ||
|
||
## Table of Contents | ||
|
||
- [Infer Schema](#infer-schema) | ||
- [Infer Schema With Conditions](#infer-schema-with-conditions) | ||
- [Why Conditional Types?](#why-conditional-types) | ||
- [Conclusion](#conclusion) | ||
|
||
## Infer Schema | ||
|
||
```TypeScript | ||
import { a, InferSchema } from 'akarjs' | ||
|
||
// Sample | for example, an object-schema | ||
const createTodo = a.object({ | ||
title: a.string().min(3), | ||
completed: a.boolean().optional(), | ||
}) | ||
|
||
type CreateTodo = InferSchema<typeof createTodo> | ||
|
||
/* | ||
/// Infers as: | ||
type CreateTodo { | ||
title: string; | ||
completed: boolean | undefined; | ||
} | ||
*/ | ||
|
||
``` | ||
|
||
## Infer Schema With Conditions | ||
|
||
```TypeScript | ||
import { a, InferSchemaWithConditions } from 'akarjs' | ||
|
||
// conditional for types | ||
const updateUser = a.object({ | ||
name: a.string().min(3), | ||
age: a.number().optional(), | ||
role: a.enum(['customer', 'vendor'] as const).optional(), | ||
}) | ||
|
||
type UpdateUser = InferSchemaWithConditions<typeof updateUser> | ||
|
||
/* | ||
/// Infers as: | ||
type UpdateUser { | ||
name: string; | ||
} & { | ||
age?: number; | ||
} & { | ||
role?: 'customer' | 'vendor'; | ||
} | ||
*/ | ||
|
||
``` | ||
|
||
## Why Conditional Types? | ||
|
||
We have noticed that when you infer a type and try to use it, you might face a problem. For example, | ||
|
||
```TypeScript | ||
const updateUser = a.object({ | ||
name: a.string().min(3), | ||
age: a.number().optional(), | ||
role: a.enum(['customer', 'vendor'] as const).optional(), | ||
}) | ||
|
||
type UpdateUserT1 = InferSchema<typeof updateUser> | ||
type UpdateUserT2 = InferSchemaWithConditions<typeof updateUser> | ||
|
||
const user1: UpdateUserT1 = { | ||
name: "Mahabub", | ||
age: undefined, // property must be declared, otherwise it might make problems | ||
role: undefined, // property must be declared, otherwise it might make problems | ||
}; | ||
|
||
const user2: UpdateUserT2 = { | ||
name: "Mahabub", | ||
// no need to add optional properties | ||
// Enjoy 👍 | ||
}; | ||
|
||
``` | ||
|
||
## Conclusion | ||
|
||
In conclusion, leveraging the power of TypeScript with our library allows for robust type inference directly from your schemas. This not only ensures type safety but also enhances code maintainability and readability. By using conditional types, you can further refine your type definitions, making your code more flexible and easier to work with. We hope this guide helps you understand how to effectively use inferred types in your projects. |
Oops, something went wrong.