TypeScript 3.8 RC release

TypeScript Candidate version 3.8 was released. TypeScript 3.8 brings many new features, including new ECMAScript standard features, only the new syntax for import / export type, and so on.

Only the type of import and export

TypeScript 3.8 added a new syntax for the only type of import and export.

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

export type { SomeThing };

Import type import only for the type of statement you want to annotate and declarations. It always will be completely erased, and therefore will not have any residual run time. Similarly, only the type of export can be used to derive the type of context, and will be deleted from the output TypeScript.

ECMAScript private field  

TypeScript 3.8 brings support for ECMAScript private field, which is part of the Stage-3 class field of the proposal, pushed by the Bloomberg completed.

class Person {
    #name: string

    constructor(name: string) {
        this.#name = name;
    }

    greet() {
        console.log(`Hello, my name is ${this.#name}!`);
    }
}

let jeremy = new Person("Jeremy Bearimy");

jeremy.#name
//     ~~~~~
// Property '#name' is not accessible outside class 'Person'
// because it has a private identifier.

And general properties (even using the modifier private property declared) different private field to keep in mind some of the rules .

Another benefit of the private field is unique, each field name to contain the class is unique. Another point worth noting is visiting any other type of private fields will cause TypeError!

More details can be found announcement:

https://devblogs.microsoft.com/typescript/announcing-typescript-3-8-rc/

Guess you like

Origin www.oschina.net/news/113272/typescript-3-8-rc-released