companion icon indicating copy to clipboard operation
companion copied to clipboard

[BUG] Variable data types are messed at several functions

Open dnmeid opened this issue 7 months ago • 0 comments

Make sure you're on the latest stable or beta build

  • [x] I have tested this on the latest stable or beta release

Is this a bug in companion itself or a module?

  • [x] I believe this to be a bug in companion and not a specific module

Is there an existing issue for this?

  • [x] I have searched the existing issues

Describe the bug

Javascript does not provide type safety, so a variable can have any type and our Companion variables follow that behavior. Some of the modules make use of this and also expressions can handle different data types to some degree. Now while investigating #3451 I have seen that a lot of our internal functions assume that a Companion variable is always a string. Some functions replace the value by a string if it is not a string, some functions return $NA when there is no result, some functions return an empty string if there is no result and so on. There seems to be no consistency.

We need to define a set of data types that we want our variables being able to handle and we need to make sure that all our functions dealing with variables can handle those data types.

My suggestion for the data types is type T = string | number | boolean | null | undefined | T[] | Record<string,T>. It might be interesting to also support Bigint from this point on.

Later it may be interesting to add more flexibility, e.g. adding Regex, allowing functions...

Steps To Reproduce

No response

Expected Behavior

No response

Environment (please complete the following information)

- OS:
- Browser:
- Companion Version:

Additional context

No response

dnmeid avatar Jun 03 '25 22:06 dnmeid