Hello,
Our team has noticed this quirk a couple times now when writing server logic in TypeScript for Nakama where sometimes if an array within a TypeScript object is created and then pushed to nothing actually gets pushed onto the array. If the array already exists within the object then pushing to it works as expected. The issue only happens if the array is newly created.
This has caused us some confusion because on the surface the code looks like it should work just fine and so when the functionality isn’t behaving as expected it is harder to track down where the issue is. We have work arounds which aren’t a problem but we’re just trying to understand why our code doesn’t work as expected.
- Nakama server framework v3.21
- Server Framework Runtime language: TypeScript
Short examples of what I’m talking about:
// Works
let inventory = userData.rewards.inventory ?? []
inventory.push(item)
userData.rewards.inventory = inventory
// Doesn't work, array is empty after "push"
userData.rewards.inventory ??= []
userData.rewards.inventory.push(item)
// Doesn't work, array is empty after "push"
if (!userData.rewards.inventory) {
userData.rewards.inventory = []
}
userData.rewards.inventory.push(refiner)
I wrote a few quick Jest test cases and running those using the same logic in the above snippet the code works just fine(items are pushed onto the arrays).
Is this something that is unique to the Goja framework and/or Go? I searched through Goja’s Github issues but couldn’t find any related cases there.
Thank you for your time!