Using identifiers in the builtins list as property names is valid Lua:
local Vector = {}
Vector.__index = Vector
function Vector.new(x,y)
return setmetatable({
x = x,
y = y
}, Vector)
end
function Vector:unpack()
return self.x, self.y
end
local v = Vector.new(2,3)
local x,y = v:unpack()
print(x,y)
If I were to write a declaration for this:
interface Vector {
new: (this: void, x: number, y: number) => Vector;
/** @tupleReturn **/
unpack(): [number, number];
}
let vec2 = {} as Vector;
let v = vec2.new(2,3);
let [x,y] = v.unpack();
let [a,b] = v["unpack"]();
which compiles to:
vec2 = {}
v = vec2.new(2, 3)
x, y = v:____unpack()
a, b = v.unpack(v)
___unpack() will cause an error. Accessing it via string index is currently a workaround.
I believe this is related to #789
Using identifiers in the builtins list as property names is valid Lua:
If I were to write a declaration for this:
which compiles to:
___unpack() will cause an error. Accessing it via string index is currently a workaround.
I believe this is related to #789