Set default values for object types

Hello,

In our TypeScript code for Functions on Objects, we’re writing a lot of object.property ?? 0 code, where we handle the case of property being undefined to “force it” to a specific default value.

Is there a way how we can set this default property in the ontology? So that we ensure that it’s never undefined and simplifies our code by just using object.property?

Thank you,
Lukas

1 Like

You can set the property as Required (docs). Then you can set any defaults in the pipeline/actions. I’m not sure if this actually changes the TS interface that functions generates but it does mean you should just be able to use the non-null assertion operator instead that should be a lot easier (myobject.name!).

1 Like

Awesome, thanks @Ben for your quick answer. We’ll try that out.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.