Created
February 20, 2023 20:59
-
-
Save Arkamis/6ca6ba1d3088843b0f682b4c73464b48 to your computer and use it in GitHub Desktop.
Add prefix key to an object but excluding some parameters
This file contains hidden or 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
type PrefixKey<T, Prefix extends string> = { | |
[K in keyof T as `${Prefix}_${string & K}`]: T[K] | |
} | |
type OmitPrefixed< | |
T, | |
Prefix extends string, | |
Keys extends Extract<keyof T, string> | |
> = { | |
[K in keyof T as K extends Keys ? never : `${Prefix}_${string & K}`]: T[K] | |
} | |
type AddPrefixExcept< | |
T, | |
Prefix extends string, | |
Keys extends Extract<keyof T, string> | |
> = OmitPrefixed<T, Prefix, Keys> & { | |
[K in Keys]: T[K] extends string ? `${Prefix}_${T[K]}` : T[K] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment