scala-js-ts-importer
scala-js-ts-importer copied to clipboard
Support for object type literal
In case of
[info] Running org.scalajs.tools.tsimporter.Main d3.d.ts d3.scala
Parse error at 1642.48
identifier expected
export function ordinal<Domain extends { toString(): string }, Range>(): Ordinal<Domain, Range>;
Oh my! That's not even an object type. It's a type refinement!
Possible solution: a) do not support: exception b) ignore refinement c) ignore refinement if toString d) emit type refinement (does scala support it? generate trait?
In case of d3.d.ts: Domain and Range are generic type arguments, they are placeholders for the types you need to provide rather than actual concrete types. Domain can be any type that has a toString. Have no idea how to handle it proper.
@sjrd @spaced Would this not be the same?
export function ordinal<Domain extends { toString(): string }, Range>():
Ordinal<Domain, Range>;
->
def ordinal[Domain <: { def toString(): String }, Range]()
: Ordinal[Domain, Range]
I'm parsing it successfully in my fork (but ignoring it - treating it as js.Any), as rendering it to the above mentioned Scala seemed to be difficult...
One might think so, but refinement types with arbitrary terms for js.Any are not really supported, because calling such members results in so-called reflective calls, which cannot be emitted correctly for JavaScript types.