Skip to content

Bad types for built-in SpecialKeys #427

@znotfireman

Description

@znotfireman

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions