There are a lot of things that annoy me and have not been fixed:
function lib.set_properties(properties: {[string]: any}, ...: Instance)
for _, instance: Instance in {...} do
for property, value in properties do
local success, errormessage = pcall(function()
instance[property] = value
end)
if not success then warn(errormessage) end
end
end
Here I’ve made a pcall function so that the code doesn’t break when trying to set the property of the instance. Property could be any string so it’s unsafe. Sadly the typechecker doesn’t allow this even though I put it into a pcall.
Next up, type refinement for if return statements is nice, but it doesn’t work with continue statements… I use a lot of continue statements and this is absolutely annoying.
People have listed this before but functions like :FindFirstChild return type Instance instead of Instance? which again, stops certain functionality.
Another thing that I dislike is that when I use :: on a variable, the other lines don’t use the new type given by ::, even when the variable doesn’t get changed. SO I have to use :: on EVERY LINE that uses the variable that could be some type or nil. Or I could put an assert above all of those lines, but that’s extra code that should not be required.
And lastly, why do I always have to stop my functions with another return statement if the return type of the function is some type or nil?
function lib.index_of_instance_in_array(array: {any}, instance: Instance): number?
for i, array_instance: any in ipairs(array) do if array_instance == instance then return i end end
return
end
this would error if I got rid of the return keyword at the end of the function. In my opinion this is just code smell and should automatically return nil at the end of the function if the function has a return type other than nothing.
Should I make a bug report out of this?