microsoft / microsoft/TypeScript

Option to report errors enabled by `useDefineForClassFields`, but still transpile using assignment semantics

Open
#56,298 4 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔍 Search Terms

"useDefineForClassFields", "class fields errors"

✅ Viability Checklist
⭐ Suggestion

Add an option to have TSC generate the same errors it currently generates for useDefineForClassFields = True, but while still continuing to transpile fields using the non-spec-compliant assignment semantics.

📃 Motivating Example

We must run TS with useDefineForClassFields = false, because we find the output code size of define semantics unacceptably large.

We want to be certain that our code continues to behave the same way when we are able to ship this code to environments that understand class fields without transpilation.

We want to eliminate from our code base all cases where field definitions behave differently between the 2 semantics, and then prevent them from ever returning.

To do this, it would be extremely helpful if TSC could report errors for code that would behave differently with define semantics, but also continue transpiling with assign semantics.

💻 Use Cases
  1. What do you want to use this for?
  2. What shortcomings exist with current approaches?
  3. What workarounds are you using in the meantime?

For 1:

see the Motivating Example.

For 2 & 3:

The only workaround I know of is to run TSC twice with different options, once for the output we want and once for the errors we want. This is prohibitively expensive to do at scale.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing useDefineForClassFields compiler option and the two class-field emit modes described in the issue. Compare the diagnostics produced with define semantics against assignment-semantic output, then identify how a separate checking option could preserve those diagnostics without changing emitted JavaScript; no file or test is named, so completion would require adding coverage for both modes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.