How should I define a Kotlin wrapper for a TypeScript interface with an optional functions? I’m pla...
a
How should I define a Kotlin wrapper for a TypeScript interface with an optional functions? I’m playing around with writing a Kotlin/JS wrapper for Monaco, and it has an interface, Environment, for configuration. The
getWorker()
and
getWorkerUrl()
functions are optional.
Copy code
export interface Environment {
  /**
  * A web worker factory.
  * NOTE: If `getWorker` is defined, `getWorkerUrl` is not invoked.
  */
  getWorker?(workerId: string, label: string): Promise<Worker> | Worker;
  /**
  * Return the location for web worker scripts.
  * NOTE: If `getWorker` is defined, `getWorkerUrl` is not invoked.
  */
  getWorkerUrl?(workerId: string, label: string): string;
a
Copy code
external interface Environment {
    val getWorker: ((String, String) -> Promise<Worker>)?
    val getWorkerUrl: ((String, String) -> String)?
}
https://pl.kotl.in/G2-3e09e8
a
nice one, cheers!
🫂 1