im stuck figuring out how to fix this
type data = {
value: number,
}
local function test(arg: data | {data})
if typeof(arg) == "table" and not arg.value then
else
print(arg.value)
end
end
im stuck figuring out how to fix this
type data = {
value: number,
}
local function test(arg: data | {data})
if typeof(arg) == "table" and not arg.value then
else
print(arg.value)
end
end
Im pretty sure its because the union type contradicts each other and i dont know the solution
Someone correct me if im wrong because ive just gotten a break from coding
sorry? you made a check that arg has type “table” so its type was refined to be {data}. you cant access arg.value then, only arg[index].value
Completely drop the union. It should only be arg: {data}. If you only have one data value, then simply let it be an array with one value, no need to complicate things by unionizing one data type and an array of data types. You would also change the function body to match the new types instead of manually checking the type of arg after removing the union
ok then, ill prob just make another function that accepts a table of data instead and the other one to only accept one
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.