Can not pass a generic type to subtype function

How can I pass fooB to funA

blog : Enhanced Ergonomics for Record Types | ReScript Blog

playground : ReScript Playground

type a = {
  name: string,
  age: int,
}

type b<'t> = {
  ...a,
  foo: 't,
}

type c = {
  ...a,
  foo:string,
}

let funA = (foo: a) => {
  Console.log(foo)
}


let fooB: b<int> = {
  name: "rsb",
  age: 12,
  foo: 1,
}

let fooC :c = {
  name: "rsb",
  age: 12,
  foo: "c",
}

funA(fooC :> a)

// ERROR: Type b<int> is not a subtype of a
funA(fooB :> a)
3 Likes

Since PR introducing this feature doesn’t state anything about type variables and I couldn’t find anything about it in the docs, I don’t think it’s supported. But I really don’t know.

@cristianoc Are type variables in record type coercion supported?

1 Like

This is too crazy… :sweat_smile:

For now you can provide your own type conversion function:

external bToA: b<'t> => a = "%identity"

funA(fooB->bToA)
3 Likes

No support for type variables in the current implementation.
It could be supported in principle.

3 Likes