Created
February 11, 2022 17:18
-
-
Save debkanchan/c9156f81a76b0ede4ad5192e6ec712f0 to your computer and use it in GitHub Desktop.
Nested Map of a type in js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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