How to ensure function returns empty array in Workshop variable

I want the variable to be an empty array [] when the function returns an empty array.
Is there a way to achieve this?

I’m defining a typescript function with a return type of string[] and assigning it to the workshop variable.

Simple example:

    @Function()
    public getEmptyArray(): string[] { return []}

However, when the function returns an empty array, the variable becomes an “empty object set.”

workshopVariable

I want the result to be like this.

emptyArrayExample

Hi @haru, I’m seeing the same, unexpected behavior with a function-backed empty string array. One potential solution appears to be composing a new string array from the “Empty object set” string array via a variable transformation (see below). Out of curiosity, can you please provide more context for why your use case is using this and any issues you’re seeing with the “Empty object set” being used as an empty string array?

2 Likes

+1 to @Joel’s solution to compose with another array as an immediately available workaround.

This is indeed the current behavior, and something we’d like to change soon. Out of safety to avoid breaking some current usage that unexpectedly relies on this, we’ll soon offer the ability to update your variable definition to opt into new behavior to fix this issue.

1 Like

Hi @evanj, thanks for letting us know about the planned fix. I understand that considering the impact on existing applications is a significant task. I hope the fix works out well.

Hi @Joel, thanks for your reply. Your solution seems to be relatively easy to implement in my business app. I’ve tried it out and it’s working well.

I was mainly struggling with two situations due to this issue:

  1. When I passed the variable as an argument to another function, the function stopped working properly.
  2. When I set the variable to the “SELECTED VALUES” of a string selector, the behavior of the string selector became strange, specifically, the string selector became hidden.
1 Like

Hey @haru - this should be fixed now. New variables will automatically have the fixed behavior, while existing variables will allow the behavior to be upgraded:

1 Like