Is it possible to do something like this? Specific...
# javascript
d
Is it possible to do something like this? Specifically asking for the options part, as I am currently using
dynamic
, and I don't like the un-safety.
Copy code
external interface GraphvizProps : RProps {
  var dot : String
  var options: {width: number, height: number}
 }
d
Copy code
external interface GraphvizProps : RProps {
  external interface Options {
    var width: Int
    var height: Int
  }
  var dot : String
  var options: Options
 }
d
this gives
Non top-level "external" declaration
d
Ah, you don't need the "external" on nested declarations
d
Thanks, that worked out! However, now I am struggling to implement an object, which satisfies this interface. What do I put in the options part?
Copy code
Graphviz {
                attrs.dot = "blabla"
                attrs.options = ???
            }
d
Unfortunately there is no easy syntax in Kotlin to implement an external interface via a plain JS object. You either have to write a class that implements it or you use a helper function with the
js
function.
d
From my limited understanding it seems to me, that it should be possible to use an
object
implementing the interface, but I am unable to figure out the correct syntax
d
That would be
Copy code
object : MyInterface {
  override var foo = 3
}
However that creates a "class" (implemented in JS as a function) with a prototype and everything instead of just a plain object.
d
I see. At least it corrects me if I misspell
width
. Thanks for the insights!