Skip to content

Typed element creation #25

Open
Open
@georgefst

Description

Would it be possible to add a method to IsElement for getting the element's tag? This would allow for safer element construction. I've ended up implementing this downstream, but it'd be tedious to do for the entire API:

createElementTyped :: forall a. (IsElement' a, PFromJSVal a) => Document -> JSM a
createElementTyped doc = unsafeCastTo pFromJSVal =<< createElement doc (elementTag @a)
class (IsElement a) => IsElement' a where
    elementTag :: Text
instance IsElement' HTMLCanvasElement where
    elementTag = "canvas"
instance IsElement' HTMLImageElement where
    elementTag = "img"
instance IsElement' HTMLLinkElement where
    elementTag = "link"

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions