What's the correct way to instantiate a class that...
# javascript
e
What's the correct way to instantiate a class that accepts an interface as constructor argument? Example in TS:
Copy code
export interface DynamicBufferOptions {
  encoding?: BufferEncoding;
  factor?: number;
  fill?: string | Buffer | number;
  size?: number;
}

export class DynamicBuffer {
  constructor(options: DynamicBufferOptions);
}
In KT the interface is translated to
Copy code
external interface DynamicBufferOptions {
  var encoding: String? /* "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "base64url" | "latin1" | "binary" | "hex" */
    get() = definedExternally
    set(value) = definedExternally
  var factor: Number?
    get() = definedExternally
    set(value) = definedExternally
  var fill: dynamic /* String? | Buffer? | Number? */
    get() = definedExternally
    set(value) = definedExternally
  var size: Number?
    get() = definedExternally
    set(value) = definedExternally
}
Copy code
jso<DynamicBufferOptions> {
  encoding = "utf8"
}
This seems good enough. But is there a way to keep the interface/class immutable?
a
Right now, we don't have any tool or API for it, but we are working on a plugin that will help to create such interfaces with immutable properties.
🤪 1
e
Thanks @Artem Kobzar! That's good news