Skip to content

Commit

Permalink
doc: update typescript builder pattern & navbar & landing page config
Browse files Browse the repository at this point in the history
  • Loading branch information
mildronize committed May 17, 2024
1 parent 0f7f1c8 commit ee7b976
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 7 deletions.
7 changes: 4 additions & 3 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ export default defineConfig({
{
text: "Examples",
items: [
{ text: "Markdown Examples", link: "/markdown-examples" },
{ text: "Runtime API Examples", link: "/api-examples" },
{ text: "TypeScript Examples", link: "/typescript"}
// { text: "Markdown Examples", link: "/markdown-examples" },
// { text: "Runtime API Examples", link: "/api-examples" },
{ text: "TypeScript", link: "/typescript"},
{ text: "Use Cases", link: "/use-cases"},
],
},
],
Expand Down
8 changes: 4 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ hero:
tagline: Ready to use design Pattern for type-safe approach in modern typescript
actions:
- theme: brand
text: Markdown Examples
link: /markdown-examples
text: Starting Reading
link: /typescript
- theme: alt
text: API Examples
link: /api-examples
text: Use Cases
link: /use-cases

features:
- title: Feature A
Expand Down
54 changes: 54 additions & 0 deletions docs/typescript.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,59 @@
---
outline: deep
---

# TypeScript

After examining the code of several well-known open-source projects such as Zod, tRPC, Hono, Elysia, and ts-odata-client.

## TypeScript Config
Use strict

## Use literal instead of string


## Use object rather than list/array
## Use tuple rather than list/array
## Use builder pattern

```ts twoslash
class Inventory<Items extends Record<string, unknown> = {}> {

items: Items = {} as Items;

add<NewItem extends Record<string, unknown>>(value: NewItem) {
this.items = {
...value as unknown as Items
}
return this as Inventory<Items & NewItem>;
}
}

const inventory = new Inventory()
.add({
hello: 'world',
}).add({
typescript: 5.1,
numbers: [23, '123']
});

console.log(inventory.items.typescript)


type A = typeof inventory.items;
// ^?






//
```

## Use predicate function instead of plain object
## Use function overload

```ts twoslash
console.log('hello')
// ^?
Expand Down
3 changes: 3 additions & 0 deletions docs/use-cases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Use Cases

test

0 comments on commit ee7b976

Please sign in to comment.