I’ve found a few bugs and have a few suggestions that I’m not sure are known of yet but wanted to talk about them anyway.
I got a few crashes from doing stuff like this when I require and try to use these classes (because when I tried to export AFTER declaring my module, it didnt want to work)
export type MyClass = TEMP
--... setup
type TEMP = typeof(module.new())
return module
I have tried other methods of getting my class to work but meh, everything always crashes studio.
And I also noticed that templated functions I guess aren’t working yet, so I wasn’t able to get appropriate type checking for this.
local ifn: <T, U>(any, T, U) -> T | U = function(a, b, c)
if a then
return b
else
return c
end
end
I also wonder if templated calls will be a thing. Would be interesting to see stuff like this:
local result: Folder = parent:WaitForChild<Folder>("folderName")
local attachments: Array<Attachment> = char:GetDescendants<Attachment>()
As for type safety, I do enjoy how it gives warnings, although the false positives are a bit difficult to deal with. For example, some properties of an object may be nil, but I believe sometimes it is better to give benefit of the doubt when accessing things like children by name or stuff like PrimaryPart
when it is assumed that it already exists. There are also times where it just doesn’t want to show autocomplete for the types I have assigned. example:
local root: BasePart? = model.PrimaryPart
while not root do
model:GetPropertyChangedSignal("PrimaryPart"):Wait()
root = model.PrimaryPart
end
print(root.Velocity) --warnings
local established: Part = root --also warnings
local part: Part = workspace.Baseplate --warnings for accessing child maybe could be ignored?
Other examples:
type Array<T> = {T}
local hinges: Array<HingeConstraint> = {}
for _, item: Instance in next, obj:GetChildren() do
if item:IsA("HingeConstraint") then
hinges[#hinges + 1] = item --warnings here for some reason
end
end
I was also thinking of maybe adding something like as
and is
operators to cast or check types, example for above:
if item is HingeConstraint then
hinges[#hinges + 1] = item as HingeConstraint --or make the casting implicit since we did a check with "is"
end
Enums also are for some reason not behaving properly.
local state: Enum.UserInputState = Enum.UserInputState.Begin --warning from type setting, when deducing, uses EnumItem anyway
local state: EnumItem = Enum.UserInputState.Begin --works but doesnt mark specific enums
Also, since the deprecation of __meta, it makes it difficult to standardize class types. You might have, for example, a constructor that is called like this:
abc.new = function(
parm1: number?
): abc
return setmetatable({Value = parm1 or 0}, meta)
end
and then make a typing for abc
with typeof()
, but it will usually say that Value
is number | nil
aka number?
, although this makes sure it is always a number. Althought I see that internally its represented with @metatable
, I can’t seem to use that either
I also noticed that variadic functions arent getting too much love with LuaU, so I hope to see more about them in the future.