Open 0x13479 opened 4 months ago
for attributes you could make it work like this :
type HealingButton = ButtonCommon & {
GetAttribute:
((ButtonCommon, "Class") -> ('Healing')),
health: IntValue,
}
type DamageButton = ButtonCommon & {
GetAttribute:
((ButtonCommon, "Class") -> ('Damage')),
damage: IntValue,
}
type ButtonCommon = Model & {}
type Button =
HealingButton |
DamageButton
local button: Button = {} :: any
-- Type Error: (24,4) Cannot call non-function (((Instance, string) -> any) & ((Model, "Class") -> "Damage")) | (((Instance, string) -> any) & ((Model, "Class") -> "Healing"))
if button:GetAttribute("Class") == 'Damage' then
-- Type Error: (26,8) Key 'damage' is missing from 'Model & {| |} & {| GetAttribute: (Model, "Class") -> "Healing", ... 1 more ... |}' in the type '(Model & {| |} & {| GetAttribute: (Model, "Class") -> "Damage", ... 1 more ... |}) | (Model & {| |} & {| GetAttribute: (Model, "Class") -> "Healing", ... 1 more ... |})'
print(button.damage)
end
in the above case , tagged unions work as expected . in the implementation below , they do not :
here is my ideal use case :
i have to do this since there is no typechecking for attributes , perhaps if there is a way to accomplish this , i'll be thankful if you let me know .