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
Artem Kobzar
07/18/2023, 11:42 AM
Copy code
external interface Environment {
val getWorker: ((String, String) -> Promise<Worker>)?
val getWorkerUrl: ((String, String) -> String)?
}