local Functions = {}
local function AddTyped(X: number, Y: number) => number
return X + Y
end
local function AddRuntime(X, Y)
if type(X) ~= "number" or type(Y) ~= "number" then
error("bad type boo")
end
return X + Y
end
local function AddUntyped(X, Y)
return X + Y
end
Functions["Luau Types"] = function()
return AddTyped(5, 10)
end
Functions["Runtime Types"] = function()
return AddRuntime(5, 10)
end
Functions["No Types"] = function()
return AddUntyped(5, 10)
end
require(4185109675).new(1, "Title", Functions)
Found an annoying bug. It’s not being redefined twice, as it’s in an if-else block.
Since this is an invasive change, it might be fitting to have a new extension for typed Lua files, as *.lua is going to make things default to non-typed Lua, basically breaking most existing 3rd party support. I personally suggest *.luau, but whatever it is, it should be officially supported as an option under ‘Save to File’.
As an aside, is there any chance we’ll get an array type built-in? I can see it being annoying to have to continually write type Array<T> = {[number]: T} in scripts.
This is awesome to see, really quite game-changing to be honest.
Now there’s no need to do any parameter type checking, which even with a function is a pain.
Will there be support for Roblox datatypes?
Also, the => syntax isn’t really my cuppa tea, if it was -> (like Rust) it’d be much nicer to use.
Also, as many people are mentioning not liking the syntax / thinking it’s too symbol based rather than keyword based: keep in mind that keywords aren’t free. Every keyword they add is an identifier no longer usable. It could end up making scripts harder to port if too many are added. (and yes, adding more would be necessary if you want it to make sense - for example, when specifying the return types of functions)
I do agree that some of the syntax could be more intuitive, but it really isn’t all that bad - I’m fine using it personally
I suspect since typeof() is actually a function, supporting custom types here would be a bad idea. Roblox will probably have to declare another type checking function, or maybe just accept that this breaks some stuff (I don’t even know if types are readable on run time).
workspace.ChildAdded:Connect(function(Object: Instance) => nil
end) -- Perfectly fine
However,
local x : Instance = workspace
x.ChildAdded:Connect(function(Object: Instance) => nil
end) -- W00 Argument count mismatch. Function takes 2 arguments but you passed 1
I’m guessing only primitives are currently fully supported?
Yeah, would need Rojo to support it as well as an extension to highlight .luau files. (Possibly in the future roblox could also release a language server for rojo users so we can get intellisense etc?)