type userdatas in type functions should have a __tostring metamethod
Currently there is no way to nicely provide types in errors in type functions, while I could make my own type to string function and copy it around everywhere its very cumbersome to do so. And also makes type resolution take more time, when luau already has a string version of the type.
Current Behavior:
TypeError: 'LeaderstatsCreator' type function errored at runtime:
[string "LeaderstatsCreator"]:55: value 'userdata: 0x0000000102864718' for key 'userdata: 0x0000000102864730'
is not of type 'string | number | buffer' or is a type union made up of 'string | number | buffer'
New Behavior:
TypeError: 'LeaderstatsCreator' type function errored at runtime:
[string "LeaderstatsCreator"]:55: value '"buffer"' for key '"lol"'
is not of type 'string | number | buffer' or is a type union made up of 'string | number | buffer'
Could this be formatted in the usual tostring(someuserdata) fashion with angle brackets, like:
type function printtype(t: type)
print(t)
return types.singleton(nil)
end
local a: printtype<"meow"> -- TypeError: <type: singleton string "meow">
type SomeStruct = {
cats: {
[string]: { name: string, age: number },
},
}
local somet: printtype<SomeStruct> -- TypeError: <type: table SomeStruct { cats: { [string]: { name: string, age: number } } }>
This would make type functions easier to print debug and reason through
Could this be formatted in the usual
tostring(someuserdata)fashion with angle brackets, like:type function printtype(t: type) print(t) return types.singleton(nil) end
local a: printtype<"meow"> -- TypeError: <type: singleton string "meow">
type SomeStruct = { cats: { [string]: { name: string, age: number }, }, }
local somet: printtype<SomeStruct> -- TypeError: <type: table SomeStruct { cats: { [string]: { name: string, age: number } } }>
This would make type functions easier to print debug and reason through
This issue is meant to match with how luau's type errors are formatted. Angle brackets aren't used in luau's type errors and instead single quotation marks are ''.
Could this be formatted in the usual
tostring(someuserdata)fashion with angle brackets, like: type function printtype(t: type) print(t) return types.singleton(nil) end local a: printtype<"meow"> -- TypeError: <type: singleton string "meow"> type SomeStruct = { cats: { [string]: { name: string, age: number }, }, } local somet: printtype -- TypeError: <type: table SomeStruct { cats: { [string]: { name: string, age: number } } }> This would make type functions easier to print debug and reason throughThis issue is meant to match with how luau's type errors are formatted. Angle brackets aren't used in luau's type errors and instead single quotation marks are
''.
That makes sense! I guess I was referring to when you print type userdatas directly.