scala-js-ts-importer
scala-js-ts-importer copied to clipboard
TypeScript Interfaces should generate abstract trait members
export interface GPGPUProgram {
variableNames: string[];
outputShape: number[];
params: Array<{}>;
userCode: string;
supportsBroadcasting?: boolean;
}
generates
@js.native
trait GPGPUProgram extends js.Object {
var variableNames: js.Array[String] = js.native
var outputShape: js.Array[Double] = js.native
var params: js.Array[js.Any] = js.native
var userCode: String = js.native
var supportsBroadcasting: Boolean = js.native
}
which should be
@js.native
trait GPGPUProgram extends js.Object {
var variableNames: js.Array[String]
var outputShape: js.Array[Double]
var params: js.Array[js.Any]
var userCode: String
var supportsBroadcasting: Boolean
}
At least when the declaration files are generated from TypeScript code, they can't have an implementation (no concrete definitions allowed in TS interfaces).
If they are left concrete, I they can't be overriden in subclasses:
variable outputShape cannot override a mutable variable
I'm not sure about cases in which the TypeScript declaration files only serve as type information for existing JavaScript libraries though.
I'm also wondering whether an optional value such as supportsBroadcasting? could be translated to something like this:
var supportsBroadcasting: js.UndefOr[Boolean] = js.native
But then again it might have to be left abstract.
@sbrunk I need this feature too, so opened PR #87. It is grateful if you leave some feedback on the PR.