AssemblyScript / assemblyscript

A TypeScript-like language for WebAssembly.
https://www.assemblyscript.org
Apache License 2.0
16.8k stars 655 forks source link

Support type inference on function parameters and class fields #314

Open MaxGraey opened 5 years ago

MaxGraey commented 5 years ago
class Foo {
  a = 2.0
  static readonly PI = 3.14
  constructor(public b = 1, public c = 1.0) {}
}
dcodeIO commented 5 years ago

In https://github.com/AssemblyScript/assemblyscript/commit/0e33806cf6de109816fe2c49390fad26896591c4 I noticed that, at the current point, at least static fields must have a type annotation because these are compiled lazily but might become resolved before being compiled, and there isn't a proper resolveExpression for any expression yet that we could use if there wasn't a type annotation. Hence, implementing a full-fledged resolver seems to be one requirement to make this proposal work without exceptions.

jarble commented 3 years ago

It's probably possible to do this using TypeScript's compiler API. It might also be possible to do this using Hegel, though it only works with a statically-typed subset of JavaScript.