Skip to content

Commit ff621ca

Browse files
committed
feat: add utils
1 parent 053eef1 commit ff621ca

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/utils.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
export type Unprefix<T extends Record<string, any>, Pre extends string> = {
2+
[K in keyof T as K extends `${Pre}${infer U}` ? U : never]: T[K];
3+
}
4+
5+
export type Prefix<T extends Record<string, any>, Pre extends string> = {
6+
// @ts-expect-error K in keyof T
7+
[K in keyof T as `${Pre}${K}`]: T[K];
8+
}
9+
10+
export type RenamePrefix<
11+
T extends Record<string, any>,
12+
Old extends string,
13+
New extends string,
14+
> = Prefix<Unprefix<T, Old>, New>
15+
16+
/**
17+
* A literal type that supports custom further strings but preserves autocompletion in IDEs.
18+
*
19+
* @see [copied from issue](https://github.com/microsoft/TypeScript/issues/29729#issuecomment-471566609)
20+
*/
21+
export type LiteralUnion<Union extends Base, Base = string> =
22+
| Union
23+
| (Base & { zz_IGNORE_ME?: never })
24+
25+
export type RegExpLike = RegExp | `/${string}/`

0 commit comments

Comments
 (0)