简体   繁体   中英

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 (aka 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 ReadonlyArray<string> | undefined

How can I update this array from my Function?

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM