Skip to content

Instantly share code, notes, and snippets.

View steven-schmoll-at's full-sized avatar

steven-schmoll-at

View GitHub Profile
@steven-schmoll-at
steven-schmoll-at / snake-to-camel-transform.ts
Created September 21, 2021 04:03
A typescript utility type to convert snake_case keys of an interface, to camelCase
/**
* Converts a type string from a snake_case string to PascalCase.
* This will convert all snake case strings including strings with no underscores, or many
*/
export type PascaleFromSnake<String extends string> = String extends `${infer First}_${infer Rest}` ? `${Capitalize<Lowercase<First>>}${PascaleFromSnake<Rest>}` : Capitalize<Lowercase<String>>
/**
* Converts a type string from a snake_case string to camelCase.
* This will convert all snake case strings including strings with no underscores, or many
*/
@steven-schmoll-at
steven-schmoll-at / paths-of.ts
Last active February 23, 2024 16:17
A typescript type to extract the keys and sub-keys of objects as dot separated paths.
type CombineAll<T> = T extends {[name in keyof T]: infer Type} ? Type : never
type PropertyNameMap<T, IncludeIntermediate extends boolean> = {
[name in keyof T]: T[name] extends object ? (
SubPathsOf<name, T, IncludeIntermediate> | (IncludeIntermediate extends true ? name : never)
) : name
}
type SubPathsOf<key extends keyof T, T, IncludeIntermediate extends boolean> = (
`${string & key}.${string & PathsOf<T[key], IncludeIntermediate>}`