Created
January 19, 2022 09:09
-
-
Save cheshirecode/550c7fecd3d665db2a975fb24405b09a to your computer and use it in GitHub Desktop.
Typescript generic filtering of object keys by prefix/return
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
// FilterPrefixedKeys<{ a1, b1 }, 'a'> == { a } | |
export type FilterPrefixedKeys<T, S extends string> = T extends `${S}${infer _X}` ? T : never | |
// https://stackoverflow.com/questions/69038001/remove-string-from-template-literal-types-in-typescript | |
// GetPostPrefixSubstring<{ a1, b}, 'a'> == { 1 } | |
export type GetPostPrefixSubstring<T, S extends string> = T extends `${S}${infer X}` ? X : never |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment