You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! I've been working with attributes a lot recently, and occasionally I'll get into some trouble when I misconfigure an instance. Since GetAttribute returns an "any" instead of an "unknown?", sometimes I'll forget to set up the proper handling for these kind of situations - typically leading to weird errors at later points in the code.
Let's assume I have an attribute called "Id" which I'm supposed to store as a number but occasionally forget and store as a string, and soemtimes forget to add at all.
Current behavior:
localidArray: {number} = {}
functionaddInst(inst: Instance)
table.insert(idArray, inst:GetAttribute("Id")) --returns an any with no issues raised, even though it could be null / stringend
Ideally, the above should be flagged as an error - something that can only be worked around through refining the type. For example:
localidArray: {number} = {}
functionaddInst(inst: Instance)
localid=inst:GetAttribute("Id") -- returns an unknown?iftype(id) =="number" thentable.insert(idArray, id)
elseerror(`inst "(inst:GetFullName())" has a bad Id attribute value`)
endend
As attributes are pretty widely used, I think there might be a lot of hidden bad-type handling as a result. Adding this change would in my opinion lead to a safer overall dev ecosystem + prevent the naturally occuring mistakes that type checkers are meant to protect from.
Thank you!
The text was updated successfully, but these errors were encountered:
Hello! I've been working with attributes a lot recently, and occasionally I'll get into some trouble when I misconfigure an instance. Since GetAttribute returns an "any" instead of an "unknown?", sometimes I'll forget to set up the proper handling for these kind of situations - typically leading to weird errors at later points in the code.
Let's assume I have an attribute called "Id" which I'm supposed to store as a number but occasionally forget and store as a string, and soemtimes forget to add at all.
Current behavior:
Ideally, the above should be flagged as an error - something that can only be worked around through refining the type. For example:
As attributes are pretty widely used, I think there might be a lot of hidden bad-type handling as a result. Adding this change would in my opinion lead to a safer overall dev ecosystem + prevent the naturally occuring mistakes that type checkers are meant to protect from.
Thank you!
The text was updated successfully, but these errors were encountered: