Enums and String literal union types as arguments in Functions on Objects

When programming functions on the ontology, we often face complex function signatures due to the level of parameterization we want to enable in our applications. Very often, certain function arguments are options for the behavior of a function. Currently, these options must be given as a string and are not apparent from the function signature.

In Python (e.g. FastAPI), one would use Enums for this purpose. In Typescript, also string literal union types are a thing. Unfortunately, we cannot reduce the complexity of our function signatures by typing options and in the best case provide the necessary info as a doc string.

Therefore, I propose to either enable Enums / String literal union types, or provide an “Options” type that wraps around the respective values to make it understandable for the Ontology.

I’d imagine the usage something like this:

@Function()
public aFunctionDependingOnOptions(objects: ObjectSet<...>, status: "new"|"active"|"released"): boolean {
...
}

or

@Function()
public aFunctionDependingOnOptions(objects: ObjectSet<...>, status: Options<"new"|"active"|"released">): boolean {
...
}

or

enum statusOptions{
    new = "new",
    active = "active",
    released = "released"
}

@Function()
public aFunctionDependingOnOptions(objects: ObjectSet<...>, status: statusOptions): boolean {
...
}

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