Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Can not pass a generic type to subtype function

$
0
0

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)

Viewing all articles
Browse latest Browse all 2592

Trending Articles