E4008

E4008#

FFI function cannot have type parameters.

Erroneous Example#

pub extern "js" fn id[T](x : T) -> T = "(x) => x"

The example declares an FFI function (marked extern) with a type parameter, which is not allowed.

Suggestion#

Consider using a concrete type that suits your needs:

///|
extern "js" fn int_id(x : Int) -> Int = "(x) => x"

///|
pub fn concrete_id(x : Int) -> Int {
  int_id(x)
}

For more complicated scenarios, consider adding an extra trait:

///|
pub(open) trait Ider {
  id(Self) -> Self
}

///|
impl Ider for Int with id(self) {
  concrete_id(self)
}

///|
pub fn trait_id(x : Int) -> Int {
  Ider::id(x)
}