Not sure if this counts as a bug report, scripting support, or a feature request BUT:
I noticed when setting a function to have multiple different possible parameters using roblox’s typechecking overloading feature, functions (seem to) break as soon as the function implies self as the first parameter, resulting in the overloaded values not changing when writing their corresponding type:
Expected behavior:
When fully typing in “Damage”, all of the needed variables show up. This is using a normal local function.
Actual behavior:
(Note than a.foo(self, value) does have the same expected autocomplete as the Expected behavior, as self is a variable that must be given) This is using an object.
Code that resulted in the following behaviors:
Expected, using foo()
type VersionValue = "Damage" | "Spin" | "Delete" | "Stun" | "Mix"
type func1 = typeof(
--[[Foo text!]]
function(version: "Spin"): any
return nil
end
)
type func2 = typeof(
--[[Foo text!]]
function(version: "Stun", person: any): any
return nil
end
)
type func3 = typeof(
--[[Foo text!]]
function(version: "Delete", instance: any): any
return nil
end
)
type func4 = typeof(
--[[Foo text!]]
function(version: "Damage", victim: any, hitter: any): any
return nil
end
)
type func5 = typeof(
--[[Foo text!]]
function(version: "Mix", person1: any, person2: any): any
return nil
end
)
local foo: func1 & func2 & func3 & func4 & func5 = function(version: VersionValue, value: any, value2: any)
end
foo("Damage")
Actual, using a:foo()
--!strict
type VersionValue = "Damage" | "Spin" | "Delete" | "Stun" | "Mix"
type func1 = typeof(
--[[Foo text!]]
function(self: any, version: "Spin"): any
return nil
end
)
type func2 = typeof(
--[[Foo text!]]
function(self: any, version: "Stun", person: any): any
return nil
end
)
type func3 = typeof(
--[[Foo text!]]
function(self: any, version: "Delete", instance: any): any
return nil
end
)
type func4 = typeof(
--[[Foo text!]]
function(self: any, version: "Damage", victim: any, hitter: any): any
return nil
end
)
type func5 = typeof(
--[[Foo text!]]
function(self: any, version: "Mix", person1: any, person2: any): any
return nil
end
)
local a: {foo: func1 & func2 & func3 & func4 & func5} = {} :: {foo: func1 & func2 & func3 & func4 & func5}
a:foo("Damage")
Am I using typechecking wrong (am I even using the correct name for it haha), or is this something that hasn’t been caught before due to how specific it is?
(Also if the solution has something to do with metatables please let me know because I am NOT well versed in them, but it seems odd to need them for this specific scenario)
As an extra note, some people only care about autocomplete and that kind of editor help, not really about code safety. If autocomplete is your main goal, this probably won’t be that useful for you.
Luau is currently unable to properly infer the type of self, especially not when you annotate its type to any, which is essentially a typechecking opt-out.
You must properly annotate the type of self manually.
I do notice with strict it now gives a warning for putting in the incorrect type (using this code), which is good! I’ll keep the “any” thing in mind going forward.
However, the original problem still persists (hopefully this video is a better example):
Again, note that when typing in a.foo(a, “Damage”) the autocomplete shows up like the expected example. I know this doesn’t change anything coding wise, but it seems incredibly odd and specific that the autocorrect doesn’t work here
Took me a while to realize you’re on the old type solver!
Interestingly, this kind of overload selection seems to be completely absent from the new solver, which by the way I suggest you migrate to soon, as they’ll eventually remove the old solver.
I’m not entirely sure if this is a bug or just a missed feature in the new solver, but you can submit a bug report for this in Bug Reports > Studio Bugs!