Skip to content

Instantly share code, notes, and snippets.

View epranka's full-sized avatar

epranka epranka

View GitHub Profile
@epranka
epranka / dotted-notation-deep-merge.ts
Created January 30, 2024 12:28
Merge Dotted Notation objects
// Type definitions
type Split<S extends string, D extends string> = string extends S
? string[]
: S extends ''
? []
: S extends `${infer T}${D}${infer U}`
? [T, ...Split<U, D>]
: [S];
@epranka
epranka / nested-object-dotted-notations.ts
Created July 26, 2024 05:32
Nested object to the do notations array
type Primitive = string | number | boolean | bigint | symbol | undefined | null;
type PathImpl<T, K extends keyof T> = K extends string
? // eslint-disable-next-line @typescript-eslint/ban-types
T[K] extends Function // Check if it's a function
? never // Exclude functions
: T[K] extends Primitive // Check if it's a primitive value
? K // Include primitives directly
: T[K] extends Record<string, any> // Check if it's an object to traverse
? T[K] extends ArrayLike<any>