Skip to content

Instantly share code, notes, and snippets.

@chaance
Created April 13, 2021 13:34
Show Gist options
  • Save chaance/5d0d86f51fa123ad15867c0293494594 to your computer and use it in GitHub Desktop.
Save chaance/5d0d86f51fa123ad15867c0293494594 to your computer and use it in GitHub Desktop.
Weird type mapping thing
// 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