TypeScript 3.7 Language Standard Conformance ECMAScript Private Fields
Private Fields • Prevent users from relying on internals which may change • Specified by TC39 (Technical Committee 39) • Authors: Daniel Ehrenberg (Igalia), Jeff Morrison (Facebook) • Merged with class field declarations proposal • Stage 3 (Strawperson, Draft, Candidate, Finished) • Awaits feedback: https://github.com/tc39/proposal-class-fields • Available online: https://tc39.es/proposal-class-fields/ 2019/12/17
ECMAScript Syntax class Point { #x; #y; constructor(x, y) { this.#x = x; this.#y = y; } equals(point) { return this.#x === point.#x && this.#y === point.#y; } } const p1 = new Point(1, 2); const p2 = new Point(1, 2); p1.equals(p2); // true 2019/12/17
TypeScript Counterpart class Point { private x: number; private y: number; constructor(x: number, y: number) { this.x = x; this.y = y; } equals(point: Point) { return this.x === point.x && this.y === point.y; } } const p1 = new Point(1, 2); const p2 = new Point(1, 2); p1.equals(p2); // true 2019/12/17
Implementation Status • Introduced in Chrome 74 • “SyntaxError: private fields are not currently supported” in Firefox 71 • Expected with TypeScript 3.7 https://github.com/microsoft/TypeScript/issues/33352 2019/12/17
Implementation Status https://github.com/microsoft/TypeScript/issues/33925#issuecomment-542925717 2019/12/17

ECMAScript Private Fields in TypeScript 3.7

  • 1.
    TypeScript 3.7 Language StandardConformance ECMAScript Private Fields
  • 2.
    Private Fields • Preventusers from relying on internals which may change • Specified by TC39 (Technical Committee 39) • Authors: Daniel Ehrenberg (Igalia), Jeff Morrison (Facebook) • Merged with class field declarations proposal • Stage 3 (Strawperson, Draft, Candidate, Finished) • Awaits feedback: https://github.com/tc39/proposal-class-fields • Available online: https://tc39.es/proposal-class-fields/ 2019/12/17
  • 3.
    ECMAScript Syntax class Point{ #x; #y; constructor(x, y) { this.#x = x; this.#y = y; } equals(point) { return this.#x === point.#x && this.#y === point.#y; } } const p1 = new Point(1, 2); const p2 = new Point(1, 2); p1.equals(p2); // true 2019/12/17
  • 4.
    TypeScript Counterpart class Point{ private x: number; private y: number; constructor(x: number, y: number) { this.x = x; this.y = y; } equals(point: Point) { return this.x === point.x && this.y === point.y; } } const p1 = new Point(1, 2); const p2 = new Point(1, 2); p1.equals(p2); // true 2019/12/17
  • 5.
    Implementation Status • Introducedin Chrome 74 • “SyntaxError: private fields are not currently supported” in Firefox 71 • Expected with TypeScript 3.7 https://github.com/microsoft/TypeScript/issues/33352 2019/12/17
  • 6.