Skip to content

Can't use bs.as without bs.string #578

@jchavarri

Description

@jchavarri

There seems to be some issue where it's impossible to use bs.as without bs.string.

The following code:

type document
type style

external document : document = "document" [@@bs.val]
external get_by_id : document -> string -> Dom.element = "getElementById"
  [@@bs.send]
external style : Dom.element -> style = "style" [@@bs.get]
external transition_timing_function :
  style ->
  [ `ease
  | `easeIn [@bs.as "ease-in"]
  | `easeOut [@bs.as "ease-out"]
  | `easeInOut [@bs.as "ease-in-out"]
  | `linear
  ] ->
  unit = "transitionTimingFunction"
  [@@bs.set]

let element_style = style (get_by_id document "my-id")
let () = transition_timing_function element_style `easeIn

Fails with:

13 |   | `easeInOut [@bs.as "ease-in-out"]
                      ^^^^^
Error (warning 101 [unused-bs-attributes]): Unused attribute: bs.as
This means such annotation is not annotated properly.
for example, some annotations is only meaningful in externals

It can be fixed by adding bs.string attribute:

type document
type style

external document : document = "document" [@@bs.val]
external get_by_id : document -> string -> Dom.element = "getElementById"
  [@@bs.send]
external style : Dom.element -> style = "style" [@@bs.get]
external transition_timing_function :
  style ->
  ([ `ease
   | `easeIn [@bs.as "ease-in"]
   | `easeOut [@bs.as "ease-out"]
   | `easeInOut [@bs.as "ease-in-out"]
   | `linear
   ]
  [@bs.string]) ->
  unit = "transitionTimingFunction"
  [@@bs.set]

let element_style = style (get_by_id document "my-id")
let () = transition_timing_function element_style `easeIn

But this should not be necessary, as poly variants already compile to strings.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions