Skip to content

Instantly share code, notes, and snippets.

@debkanchan
Created February 11, 2022 17:18
Show Gist options
  • Save debkanchan/c9156f81a76b0ede4ad5192e6ec712f0 to your computer and use it in GitHub Desktop.
Save debkanchan/c9156f81a76b0ede4ad5192e6ec712f0 to your computer and use it in GitHub Desktop.
Nested Map of a type in js
type NestedMap<V> = { [key: string]: V | NestedMap<V> };
let myObj: NestedMap<number> = {} //valid
myObj = {a: 5} //valid
myObj = {a: 'sdfsdf'} //invalid
myObj = {a: 5, b: { c: 2 }} //valid
myObj = {a: 5, b: { c: 'foobar' }} //invalid
myObj = {a: 5, b: { c: { d: { e: { f: { g: 5}}}}}} //valid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment