I'm trying to use this javascript library from my scala.js app (simplified runnable example).
I can successfully use some parts of the api, but for other parts I'm having trouble determining the correct type signatures for my Scala facade.
For example, if a javascript function returns { text: 'June 5th 1998', ... }
I can define scala.js classes to represent the function and the following succeeds:
class Value extends js.Object {
def date(): js.Dictionary[Int] = js.native
}
object nlp extends js.Object {
def sentences(text: String): js.Array[Sentence] = js.native
def value(text: String): Value = js.native
}
nlp.value("I married April on June 6th 1998.").date()
However I have less luck if the javascript returns an array of the same (e.g.[{ text: ...}, { text: ...}]
), or even if it returns a simple String
(e.g."June 5th and June 6th"
as the following compiles but fails at runtime with Uncaught TypeError: arg1$4.text is not a function
:
class Sentence extends js.Object {
def text(): String = js.native
def values(): js.Array[Value] = js.native
}
val sentences = nlp.sentences(splittableText)
sentences.map( sentence => sentence.values() )
// Or `sentences.map( sentence => sentence.text() )`
How can I use this javascript api from scala.js?
Thanks very much for taking a look.