Skip to content

Design Meeting Notes, 8/13/2024 #59624

Open
@DanielRosenwasser

Description

@DanielRosenwasser

Ordering Parameter Properties and Class Fields

#45995

  • When we adjusted our class field emit (with useDefineForClassFields), we also adjusted the relative ordering of class fields and parameter properties.

  • Under JS, class fields run before the body of the constructor.

  • Under TS, previously, class fields ran after parameter properties, but before the body of the constructor.

  • Under useDefineForClassFields we error on any access to parameter properties, but otherwise it's fine.

  • Should we adjust the ordering to be consistent?

  • useDefineForClassFields was introduced as a legacy behavior to avoid breaks, why break people?

    • Could deprecate setting it to false.
  • We could run a PR where it always errors, see what breaks.

    • Is there an argument for making things more spec-compliant over time?
  • Is there something clever we could do with emit?

    • Witnessable side-effects.
  • The tough part is that most codebases that would be affected by running on GitHub won't be uncovered. Typically these are more mature codebases.

  • Could always do a codemod. We typically rely on quick fixes here.

    // Before
    class A {
        x = 1;
        constructor(public y: number) {
            console.log(this.y);
        }
    }
    // After
    class A {
        declare x;
        constructor(public y: number) {
            this.x = 1;
            console.log(this.y);
        }
    }
  • Some of us feel like it's a good idea to get consistent emit. Picking a date in the future to deprecate and eventually remove is the proposed plan. But need to experiment first.

  • Maybe 6.0 deprecation is the plan.

  • This has only been available since ES2022 though!

  • 6.0 deprecation = 6.5 removal, which is just over 2 years from now.

  • Aside: we should investigate parameter properties in ECMAScript.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design NotesNotes from our design meetings

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions