Skip to content

Commit 39142e8

Browse files
committed
docs(configuration): add typescript usage example
Closes #217
1 parent d77b365 commit 39142e8

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

docs/content/en/configuration.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,42 @@ export default class User extends Model {
8383
}
8484
```
8585

86+
### Typescript
87+
88+
If we are working on a Typescript project, we can infer the types of the fields, so we have intellisense.
89+
90+
#### Directly in Model
91+
```ts{}[~/models/User.ts]
92+
import Model from './Model'
93+
94+
export default class User extends Model {
95+
firstName: string
96+
lastName: string
97+
age: number
98+
99+
...
100+
}
101+
```
102+
103+
#### Using an Interface
104+
```ts{}[~/models/User.ts]
105+
import Model from './Model'
106+
107+
interface User {
108+
firstName: string
109+
lastName: string
110+
age: number
111+
}
112+
113+
class User extends Model {
114+
...
115+
}
116+
117+
export default User
118+
```
119+
120+
<alert type="info">You can use `!` operator to make non-null assertion.</alert>
121+
86122
## Changing the Primary Key
87123

88124
<alert type="info">By default, the `primaryKey` is set to `id`.</alert>

0 commit comments

Comments
 (0)