Did this get resolved? I can’t tell if I’m crazy for having memories of self working correctly during parts of the last two years. The typing on self hasn’t actually worked for me in some time, and luau seems to get lost very easily in very common module patterns when metatables or __index are invlolved.
I’ve been burning ridiculous numbers of hours trying to find reliable patterns that allow Script Analysis and auto completion to work with code unless I explicitly define all the types up front.
Very simple classes will generate inferred type definitions where
local Module = {}
Module.__index = Module
function Module:Foo()
end
function Module:Bar()
end
will end up giving you a type like
{
<a>Foo: (self:a)->(),
<b>Bar: (self:b)->()
}
with no recognition that self a, self b, and the module all share the same type and properties.
Even with --!strict on, Script Analysis understands self to be type any, so it doesn’t generate warnings.
I have code where I work around that basically the way @catgirlin_space did, or I may have the first line of every class method be
local self:SpecificClassType = self
Except now you have the problem of either needed to define the type ahead of time, or you have
type SpecificClassType = typeof(SpecificClassTable)
in your code somewhere, and that creates a new set of luau script analysis problems
I keep running into writing a bunch of code in a way that makes luau happy and me maybe even happy, but stops working (to satisfy luau) soon after.
It’s not an exaggeration that I’ve burned hundreds of hours changing my coding style over and over to get type inference, auto complete, and script analysis to work, bending code structure around what might work for luau.
I’d have gotten a lot more done if I gave up on that 2 years ago, and moved my lua editing to visual studio. Roblox Studio really really has come very far in the last few years. luau has come very far. It’s impressive, but I’m still wondering when luau is going to pay off and make for an actually smooth coding/testing/debug experience.
I’m still re-inventing lua module definition patterns over an over to try to get luau to work right.