Skip to content

Polymorphic variant coercion to string: add warning/docs. #6903

Open
@remitbri

Description

@remitbri

Hi

ReScript version: v11.x.x

When using plain variants with an @as, coercing to string produces the expected result. E.g

type plain = 
  | Foo 
  | @as("js") ReScript
let plainToJs = (x: plain) => (x :> string)
let plainOk = plainToJs(ReScript) // "js"

When using polymorphic variants with an @as, coercing to string produces an unexpected result

type poly = [#foo | @as("js") #rescript]
let polyToJs1 = (x: poly) => (x :> string)
let poly1NotOk = polyToJs1(#rescript) // "rescript" 

I'm not sure whether this is expected or if I'm supposed to write

let polyToJs2 = (x: poly) =>
  switch x {
  | #rescript => "js"
  | _ => (x :> string)
  }

Playground here

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions