Skip to content

Commit 0e27dd1

Browse files
docs(website): improve docs on optional typing
1 parent 1b1b919 commit 0e27dd1

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export default () => [
22
{
3-
code: 'npx overmind-devtools',
3+
code: 'npx overmind-devtools@latest',
44
},
55
]

packages/overmind-website/guides/beginner/02_definingstate.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,39 @@ In JavaScript we can create all sorts of abstractions to describe values, but in
1212

1313
Let us talk a little bit about what each value helps us represent in our application.
1414

15+
### Undefined
16+
You might wonder why **undefined** is not part of the core value types. Well, there are two reasons:
17+
18+
1. It is not a serializable value. That means if you explicitly set a value to *undefined* it will not show up in the devtools
19+
2. Undefined values can not be tracked. That means if you were to iterate an object and look at the keys of that object, any undefined
20+
values will not be tracked. This can cause unexpected behaviour
21+
22+
```marksy
23+
h(TypescriptNotice, null, `When writing Typescript you should **not** use optional values for your state (**?**), or use **undefined** in a union type. In a serializable state store world **null** is the value indicating *"there is no value"*.
24+
25+
\`\`\`ts
26+
type State = {
27+
// Do not do this
28+
foo?: string
29+
30+
// Do not do this
31+
foo: string | undefined
32+
33+
// Do this
34+
foo: string | null
35+
36+
// Or this, if there always will be a value there
37+
foo: string
38+
}
39+
40+
export const state: State = {
41+
foo: null
42+
}
43+
\`\`\`
44+
45+
`)
46+
```
47+
1548
### Naming
1649

1750
Each value needs to sit behind a name. Naming can be difficult, but we have some help. Even though we eventually do want to consume our application through a user interface we ideally want to avoid naming things specifically related to the environment where we show the user interface. Things like **page**, **tabs**, **modal** etc. are specific to a browser experience, maybe related to a certain size. We want to avoid those names as they should not dictate which elements are to be used with the state, that is up to the user interface to decide later. So here are some generic terms to use instead:

packages/overmind-website/src/components/Introduction/introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ export const overmind = createOvermind(config, {
313313
Go to your terminal and use the NPM executor to instantly fire up the development tool.
314314

315315
```
316-
npx overmind-devtools
316+
npx overmind-devtools@latest
317317
```
318318

319319
Refresh the sandbox preview and you should see the devtools populated with information from the application.

0 commit comments

Comments
 (0)