Skip to main content

Deep Path

Path is a function to easily retrieve and update a possibly nested property in an (immutable) object in TypeScript. As shown in the Patch documentation, it can be quite hard to update an immutable object without helpers. That Path object allows you to specify the location of a nested property using a string:

import { Path } from '@rimbu/core';
type Person = {  name: string;  address: {    street: string;    number: number;  };};
function updateAddressNumber(person: Person, value: number): Person {  return Path.patchValue(person, 'address.number', value);}
function getPersonStreet(person: Person): string {  return Path.getValue(person, 'address.number');}

The following CodeSandbox shows more examples of how to use the Path object:

Open file below in new window with full type-check