Skip to content

About # and 'private'. Why not '#private' ? #60275

@mberdev

Description

@mberdev

Acknowledgement

  • I acknowledge that issues using this template may be closed without further explanation at the maintainer's discretion.

Comment

I was thinking about this topic : #31670

The conversation can go on.

The facts :

  • private is a Typescript keyword
  • private field does not get transpiled into #field or any constraining code, as per Typescript philosophy.
  • # is Javascript syntax.
  • # is considered awkward by many Typescript devs, because:
    • it's carried around alongside the variable name.
    • it's stealing the spot of what private would be used for in the vast majority of OOP languages.

There's got to be a way of getting the best of both.

What do you think of this ?

  • A new typescript keyword, '#private'
  • It gets transpiled into a #field
  • Example : #private field: number. Then in Typescript it's used normally: this.field = 12;. In Javascript it's compiled as this.#field = 12;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Out of ScopeThis idea sits outside of the TypeScript language design constraintsSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions