Search code examples
palantir-foundryfoundry-actions

How do I update an array property in a Palantir Foundry Ontology edit Function?


I want to modify an array property on an Object using an Ontology Function (a.k.a FoO), but I'm seeing the following error:

[typescript] Property 'push' does not exist on type 'readonly string[]'.

Looking at the generated TypeScript definition for my Object type, it looks like my array property has type ReadonlyArray<string> | undefined

How can I update this array from my Function?


Solution

  • You need to assign a new value to the property rather than manipulate the existing array in-place.

    Array properties on an object type have immutable values to make the semantics for editing an array property clear: the only way to modify the values of an array property is to assign an entirely new array value.

    If you want to manipulate the values of an array property, make a copy of it and update that (as described in the Foundry docs):

    // Copy to a new array
    let arrayCopy = [...myObject.myArrayProperty];
    // Now you can modify the copied array
    arrayCopy.push(newItem);
    // Then overwrite the property value
    myObject.myArrayProperty = arrayCopy;