Skip to content

Commit 6d3dcba

Browse files
author
Mat Dudek
committed
📝 docs: add Methods type documentation (sketch)
1 parent b6b6b5c commit 6d3dcba

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

docs/complex-types/methods.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# methods
2+
3+
In this section we will explore 🚀 all nooks and crannies behind methods types.
4+
5+
6+
7+
Diving into `methods.ts` we have these three imports
8+
9+
```ts
10+
import { EntitySchema } from "./data" // Record<string, any>
11+
import { SyncKey } from "./sync" // Opaque<string, "sync-key">
12+
import { Except } from "type-fest" // Create a type from an object type without certain keys.
13+
```
14+
15+
## Methods
16+
17+
```ts
18+
export type Methods<TSchema extends EntitySchema> = Record<
19+
string, // keys
20+
(this: TSchema, ...args: any[]) => any // values
21+
>
22+
```
23+
24+
`Methods<TSchema>`: This is a generic type called `Methods`. It takes a type parameter `TSchema`, which is expected to extend the `EntitySchema`.<br/>
25+
This means that `Methods` is a reusable type where we can use it for different EntityType. (dunno if I should explain this @TODO)
26+
27+
28+
```ts
29+
Record<string, ...>
30+
```
31+
This denotes as an __*object*__ type where keys are `strings`. Pretty logic, methods must be somehow named.
32+
33+
```ts
34+
(this: TSchema, ...args: any[]) => any
35+
```
36+
This is the type of values in the __*object*__.<br/>
37+
It indicates a function that takes Ż
38+
- `this` of type `TSchema` (the entity schema) as its first parameter. (We need to have an access to the object with data inside a function)
39+
- `..args: any[]` means any number of arguments of any type (`rest syntax`)
40+
41+

0 commit comments

Comments
 (0)