Created
April 13, 2021 13:34
-
-
Save chaance/5d0d86f51fa123ad15867c0293494594 to your computer and use it in GitHub Desktop.
Weird type mapping thing
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
// With template literal types this kind of thing is a breeze! | |
type RootActionPrefix = 'auth'; | |
type ActionType = 'LOGIN' | 'LOGOUT'; | |
type RootActionTypes = `${RootActionPrefix}/${ActionType}`; | |
// Is there any sort of mapped-type magic that would let me | |
// turn this... | |
type AuthActions = | |
| { type: 'LOGIN'; user: UserNoPassword } | |
| { type: 'LOGOUT' }; | |
// ...into this? | |
type RootAuthActions = | |
| { type: 'auth/LOGIN'; user: UserNoPassword } | |
| { type: 'auth/LOGOUT' }; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment