scala-js-ts-importer icon indicating copy to clipboard operation
scala-js-ts-importer copied to clipboard

TypeScript Interfaces should generate abstract trait members

Open sbrunk opened this issue 8 years ago • 2 comments

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.

sbrunk avatar Oct 21 '17 14:10 sbrunk

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 avatar Oct 21 '17 17:10 sbrunk

@sbrunk I need this feature too, so opened PR #87. It is grateful if you leave some feedback on the PR.

exoego avatar Oct 21 '18 11:10 exoego