days
0
-23
-6
hours
-1
-1
minutes
-2
-3
seconds
-4
-8
search
Preview the newest features

TypeScript 3.8 beta adds support for ECMAScript private fields

Sarah Schlothauer
typescript
© Shutterstock / LiliGraphie

TypeScript’s popularity among JavaScript programmers makes it an essential component of modern JS development. The latest version, TypeScript 3.8 Beta, contains new features including new syntax for importing and exporting only types. Give the beta release a try and experience all of the latest features before the final release arrives.

TypeScript, the superset of JavaScript, offers minimal configuration management and IDE support, while still providing the benefit of JavaScript libraries. It adds optional static type-checking and type syntax and works with all browsers and operating systems.

Released on January 10, 2020, TypeScript 3.8 Beta includes features that users can expect to find in the final version. Give the beta a try and familiarize yourself with what is coming in the final release.

This version includes the support and collaborative efforts of the Bloomberg engineering team.

SEE ALSO: How can you make a JavaScript website successful in Google?

v3.8 beta features

Daniel Rosenwasser, TypeScript program manager, dives deep into the new features in the Microsoft announcement post.

Take a look at the recent arrival. Some of the highlights of v3.8 beta include:

Private fields

Thanks to contributions from Bloomberg, support for ECMAScript’s private fields arrives. It is currently in the third stage of development, which indicates that further refinement and feedback are needed before it is included in the formal ECMAScript standard.

Rosenwasser notes that with the introduction of private fields comes a few new rules.

  • Private fields start with a # character. Sometimes we call these private names.
  • Every private field name is uniquely scoped to its containing class.
  • TypeScript accessibility modifiers like public or private can’t be used on private fields.
  • Private fields can’t be accessed or even detected outside of the containing class – even by JS users! Sometimes we call this hard privacy.

View more information about public and private class fields in the proposal.

Syntax for importing/exporting type-only

One of TypeScript’s features is that it reuses JavaScript’s import syntax using the import elision feature. However, despite its benefits and ease of use, it could cause problems when importing a value or type, leaving it ambiguous after being exported. Import elision also caused other troublesome issues such as removing import statements that only contained imports used as types.

Now, TypeScript 3.8 beta adds a new syntax for type-only importing and exporting that will fix the aforementioned issues.

import type { SomeThing } from "./some-module.js";

export type { SomeThing };

View the original pull request on GitHub.

Miscellaneous updates

Other features and changes arriving with 3.8 beta:

  • New ECMAScript 2020 syntax: Improved syntax added to JavaScript and TypeScript 3.8: export * as utilities from “./utilities.js”;
  • Top-level await: This adds an upcoming ECMAScript feature. View the top-level ‘await’ proposal (currently in stage 3).
  • Supports  es2020 as option for module and target
  • New compiler option: assumeChangesOnlyAffectDirectDependencies
  • Breaking change: object in JSDoc is No Longer any Under noImplicitAny
  • Stricter type-checker: The type-checker now only exempts properties from excess properties checks if the property involved could potentially satisfy an index signature.

SEE ALSO: The State of JavaScript 2019: Developers love React and TypeScript

Updating TypeScript


Update and test out the newest features by downloading it via NuGet. Or, update through npm with the npm install typescript@beta  command.

As this version graduates from beta to its final release, the development team will continue fixing bugs and polishing it up for its debut. Beta testers can helpful feedback for the development team about potential bugs, errors, or issues to ensure a smooth release.

Refer to the 3.8 iteration plan for upcoming dates, notes, and current work items.

The final release of TypeScript 3.8 is planned to arrive on February 18, 2020. 

Author
Sarah Schlothauer

Sarah Schlothauer

All Posts by Sarah Schlothauer

Sarah Schlothauer is an assistant editor for JAXenter.com. She received her Bachelor's degree from Monmouth University and is currently enrolled at Goethe University in Frankfurt, Germany where she is working on her Masters. She lives in Frankfurt with her husband and cat. She is also the editor for Conditio Humana, an online magazine about ethics, AI, and technology.

Leave a Reply

avatar
400