Skip to content

Enable "useDefineForClassFields" in tsc --init #39311

Open

Description

@robpalme

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.

Activity

  1. RyanCavanaugh commented on Jun 29, 2020

    @RyanCavanaugh
    Member
  2. added a commit that references this issue on Jul 1, 2020
    c013504
  3. sandersn commented on Jul 2, 2020

    @sandersn
    Member

    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.

  4. orta commented on Jul 5, 2020

    @orta
    Contributor

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

  5. sandersn commented on Sep 18, 2020

    @sandersn
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions