Fusion icon indicating copy to clipboard operation
Fusion copied to clipboard

Bad types for built-in SpecialKeys

Open znotfireman opened this issue 10 months ago • 1 comments

It's idiomatic to type children props as [typeof(Fusion.Children)]: Fusion.Child, however this actually becomes [Fusion.SpecialKey]: Fusion.Child which allows for every special key.

Potential fix:

type BuiltinSpecialKey<K, S> = SpecialKey & {
    kind: K,
    -- this isn't necessary but might be useful
    stage: S
}

-- ...

export type Fusion = {
    -- ...
    Children: BuiltinSpecialKey<"Children", "descendants">,
    OnEvent: (eventName: string) -> BuiltinSpecialKey<"OnEvent", "observer">,
    OnChanged: (propertyName: string) -> BuiltinSpecialKey<"OnChanged", "observer">,
    Out: (propertyName: string) -> BuiltinSpecialKey<"Out", "observer">,
    Attribute: (attributeName: string) -> BuiltinSpecialKey<"Attribute", "self">,
    AttributeChanged: (attributeName: string) -> BuiltinSpecialKey<"AttributeChanged", "observer">,
    AttributeOut: (attributeName: string) -> BuiltinSpecialKey<"AttributeOut", "observer">,
    -- ...
}

Or alternatively introduce generics to SpecialKey.

znotfireman avatar Feb 26 '25 08:02 znotfireman