TypeScript 3.8 unveils new syntax for type-only imports

TypeScript 3.8 unveils new syntax for type-only imports


TypeScript 3.8 unveils new syntax for type-only imports | InfoWorld

, is now available in a beta release. The latest  upgrade emphasizes type-only imports and exports and ECMAScript standards compliance.

The release adds a new syntax for type-only imports and exports, with the intent of giving users more fine-grained control over import and elision. The import type syntax only imports declarations to be used for type annotations and declarations and always gets fully erased. The export type syntax only provides an export to be used for type contexts and is erased from TypeScript output.

TypeScript has used JavaScript’s import syntax to enable reference types. While convenient, the capability only worked because of the import elision feature, which omits TypeScript type imports when TypeScript outputs JavaScript files. However, import elision has been both insufficient and problematic.

In conjunction with import type, TypeScript 3.8 also adds a compiler flag to control what happens with imports that won’t be used at runtime: importsNotUsedAsValues.

Regarding the  for JavaScript, TypeScript 3.8 adds support for ECMAScript private fields, which is part of a for JavaScript. Public and private fields will be integrated into single, orthogonal whole, according to this proposal.

Other improvements planned for TypeScript 3.8 include:


  • JavaScript files are supported in TypeScript 3.8 by turning on the allowJs flag; type-checking of those files is supported via the checkjscode option or by adding a // @ts-check comment to the top of .js files. New JSDoc tags are leveraged for properties, because JavaScript files lack a dedicated syntax for type-checking.
  • A watchOptions field in tsconfig.json and jsconfig.json lets users tell the compiler/language service which file watching strategies to use to keep track of files and directories.
  • The general release of TypeScript 3.8 is expected in mid February. The beta can be accessed through or via NPM:

    npm install typescript@betacode