Skip to content

Instantly share code, notes, and snippets.

@Beng89
Beng89 / DotNotation.ts
Created February 2, 2022 22:29
Typescript Dot Notation
type ChildAndParent<TParent, TChild> = TParent extends string ? `${TParent}.${TChild extends string ? TChild : never}`
: TChild;
type DotNotation<T, TParent = false> = T extends object ?
{ [K in keyof T]: TParent | DotNotation<T[K], ChildAndParent<TParent, K>> }[keyof T]
: TParent
interface Test {
levelOne: {
hello: string,
levelTwo: {