Skip to content

Support type inference on function parameters and class fields #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
MaxGraey opened this issue Nov 2, 2018 · 2 comments
Open

Support type inference on function parameters and class fields #314

MaxGraey opened this issue Nov 2, 2018 · 2 comments

Comments

@MaxGraey
Copy link
Member

MaxGraey commented Nov 2, 2018

class Foo {
  a = 2.0
  static readonly PI = 3.14
  constructor(public b = 1, public c = 1.0) {}
}
@dcodeIO
Copy link
Member

dcodeIO commented Dec 4, 2018

In 0e33806 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.

@dcodeIO dcodeIO changed the title [Feature] Allow infering for default init fields & params Support type inference on function parameters and class fields May 27, 2020
@jarble
Copy link

jarble commented Dec 4, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants