-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add TagsFrom helper type * simplify TagsFrom helper * move TagsFrom tests to typegenTypes * remove unused import * Apply suggestions from code review --------- Co-authored-by: Mateusz Burzyński <mateuszburzynski@gmail.com>
- Loading branch information
1 parent
32ed8c4
commit 4314720
Showing
3 changed files
with
85 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
'xstate': minor | ||
--- | ||
|
||
The new `TagsFrom` helper type extracts the type of `tags` from a state machine when typegen is enabled: | ||
|
||
```ts | ||
const machine = createMachine({ | ||
// `tags` attached to machine via typegen | ||
tsTypes: {} as import('./machine.typegen').Typegen0, | ||
tags: ['a', 'b'], | ||
states: { | ||
idle: { tags: 'c' } | ||
}, | ||
}); | ||
|
||
type Tags = TagsFrom<typeof machine>; // 'a' | 'b' | 'c' | ||
``` | ||
|
||
If typegen is not enabled, `TagsFrom` returns `string`: | ||
|
||
```ts | ||
const machine = createMachine({ | ||
tags: ['a', 'b'], | ||
states: { | ||
idle: { tags: 'c' } | ||
} | ||
}); | ||
|
||
type Tags = TagsFrom<typeof machine>; // string | ||
``` |
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