Skip to content

Instantly share code, notes, and snippets.

@nwellis
Last active February 2, 2022 22:36
Show Gist options
  • Save nwellis/98ccd528434d22b0edf34c4dd795a95c to your computer and use it in GitHub Desktop.
Save nwellis/98ccd528434d22b0edf34c4dd795a95c to your computer and use it in GitHub Desktop.
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
type Foo = DotNotation<{
a: "hello"
b: "darkness"
c: {
d: "my"
e: "old"
f: {
g: "friend"
}
}
}>
@nwellis
Copy link
Author

nwellis commented Feb 2, 2022

Another @Beng89 💎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment