-
Notifications
You must be signed in to change notification settings - Fork 151
Description
When working with where it (to me) makes sense to restrict the field used as a tag to only a single value. This way, typos and similar can't sneak up on you when creating values of these types.
Right now, an enum has to be used, creating something like
enum SingleTypeTag
"SingleType"
end
record SingleType
where self.tealType == "SingleType"
tealType: SingleTypeTag
name:Name
kind:KindOfType
generics:{ Type }
endIt would be a lot nicer if simple string constants could be used as types directly. Then, the above could be reduced to
record SingleType
where self.tealType == "SingleType"
tealType: "SingleType"
name:Name
kind:KindOfType
generics:{ Type }
endAside from reducing the amount of code needed to write, it also is easier to read to me as the important bits now stay together. Instead of me having to "hunt down" the enum to see what the tag exactly is.
Lua language server is already capable of doing this, you also see it in Typescript. So it isn't an unknown feature. For reference, with lua language server the type is described as:
---@class SingleType
---@field tealType "SingleType"
---@field name Name
---@field kind KindOfType
---@field generics (Type)[]
local SingleType = {}It (for me) also makes the generation of type definition files easier. As Tealr would be able to just spit out the string in all 3 cases, rather than having to generate an enum specifically for teal. (The 3 cases are the html site, teal and lua language server)