Skip to content
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

Enable "useDefineForClassFields" in tsc --init #39311

Open
5 tasks done
robpalme opened this issue Jun 29, 2020 · 4 comments
Open
5 tasks done

Enable "useDefineForClassFields" in tsc --init #39311

robpalme opened this issue Jun 29, 2020 · 4 comments
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@robpalme
Copy link

Search Terms

useDefineForClassFields, tsc --init, tsconfig

Suggestion

tsc --init's generated tsconfig.json should include "useDefineForClassFields": true

Use Cases

All major web and non-web engines now ship Define-style semantics.

So the safest approach is to ensure new TypeScript projects use standard web-compatible behavior.

Examples

It looks like we just need to add one line here. I am happy to send a PR.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@RyanCavanaugh RyanCavanaugh added In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Jun 29, 2020
@RyanCavanaugh
Copy link
Member

I think this is a good idea. @ahejlsberg @DanielRosenwasser thoughts?

robpalme added a commit to bloomberg/TypeScript that referenced this issue Jul 1, 2020
@sandersn
Copy link
Member

sandersn commented Jul 2, 2020

Three concerns we should discuss:

  1. The emit is bulky for all targets <ESNext.
  2. As of 4.0, we have errors around places where [[Set]] and [[Define]] differences are observable.
  3. [[Define]] semantics are at stage 3, so strict standards compliance isn't really a motivator yet.

We have existing features with non-compliant emit, iteration for example, and errors to prevent the non-compliance from being observed, so there's precedence for prioritising good emit over standards compliance.

If we had multiple --init options, this would be the perfect addition to a "latest" init.

@orta
Copy link
Contributor

orta commented Jul 5, 2020

I added it to the recommended tsconfig base: tsconfig/bases#15

@sandersn
Copy link
Member

From discussion in the design meeting: We decided not to do this until [[Define]] semantics ship in some ES20xx spec, and that ES20xx becomes the default target in tsc --init.

Currently the default target is ES5, which we need to rethink -- in my opinion, ES2015 at least should be the default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants