Problem Statement
Remap keys of T from camelCase to snake_case at the type level.
Explanation
Split names at capital letters with template literal types and rebuild using underscores. Apply key remapping in a mapped type using “as”. Keep in mind: purely type-level—no runtime rename happens automatically.
Code Solution
SolutionRead Only
type ToSnake<S extends string> = S extends `${infer H}${infer T}`
? H extends Lowercase<H>
? `${H}${ToSnake<T>}`
: `_${Lowercase<H>}${ToSnake<T>}`
: S;
export type SnakeKeys<T> = {
[K in keyof T as K extends string ? ToSnake<K> : K]: T[K]
};
type A = { userId: string; isAdmin: boolean };
type B = SnakeKeys<A>; // { user_id: string; is_admin: boolean }