// weakly typed variant // note: adding `as const` will not make it strongly typed because of a limitation/bug in `KeyPathsOf` constkeypath_to_yahaha = ["kill", "your", "self", 2, 1, "noice"] setKeyPath(data, keypath_to_yahaha, "YEEEE")
// strongly typed variant conststrong_keypath_to_yahaha: ["kill", "your", "self", 2, 1, "noice"] = ["kill", "your", "self", 2, 1, "noice"] // @ts-ignore: since `data` is declared as `const`, we cannot technically assign the value `"YOSHIII"` to the original `"YAHAHA"`. setKeyPath(data, strong_keypath_to_yahaha, "YOSHIII")
set the value of nested
obj
at a givenkey-path
, and then returns the object back.Example