TypeScript 3.4 arrived with the new –incremental flag, higher order type inference & more

Share
  • April 1, 2019

TypeScript has been surprising lately with its significant growth, as reports have shown over the past few months.

But today we are not going over another report that praises TypeScript’s rise! Today we have a look at the news release.

TypeScript 3.4 is live and it brings some important updates and interesting new features including the new flag called --incremental, higher order type inference and many more.

Let’s have a look.

The new features

Faster subsequent builds with the --incremental flag Tells TypeScript to save information about the project graph from the last compilation. The next time TypeScript is invoked with --incremental, it will use that information to detect the least costly way to type-check and emit changes to your project.

Higher order type inference from generic functions – During type argument inference for a call to a generic function that returns a function type, TypeScript will, as appropriate, propagate type parameters from generic function arguments onto the resulting function type.

Improvements for ReadonlyArray and readonly tuples – Making it a little bit easier to use read-only array-like types:

  • A new syntax for ReadonlyArray: Introducing a new syntax for ReadonlyArray using a new readonly modifier for array types.
function foo(arr: readonly string[]) {
    arr.slice();        // okay
    arr.push("hello!"); // error!
}
  • readonly tuples: New support for readonly tuples. We can prefix any tuple type with the readonly keyword to make it a readonly tuple, much like we now can with array shorthand syntax.
  • readonly mapped type modifiers and readonly arrays: Will automatically convert array-like types to their corresponding readonly counterparts.

const assertions – Introducing a new construct for literal values called const assertions. Its syntax is a type assertion with const in place of the type name (e.g. 123 as const). When you construct new literal expressions with const assertions, we can signal to the language that:

  • no literal types in that expression should be widened (e.g. no going from "hello" to string)
  • object literals get readonly properties
  • array literals become readonly tuples

Type-checking for globalThis New support for type-checking ECMAScript’s new globalThis – a global variable that, well, refers to the global scope. Unlike the above solutions, globalThis provides a standard way for accessing the global scope which can be used across different environments.

Convert parameters to destructured object – Implemented a new refactoring to convert existing functions to use this “named parameters” pattern.In the presence of multiple parameters, TypeScript will provide a refactoring to convert the parameter list into a single destructured object. Accordingly, each site where a function is called will also be updated. Features like optionality and defaults are also tracked, and this feature also works on constructors as well.

SEE ALSO: JavaScript reigns supreme while TypeScript and Julia surprise with their growth in new RedMonk report

Head over to the official release notes to find out more about all the new features in TypeScript 3.4.

But that is not all!

Although the TypeScript team avoids introducing breaking changes as much as possible, there are some going live with this release so make sure to check them out here.

The post TypeScript 3.4 arrived with the new –incremental flag, higher order type inference & more appeared first on JAXenter.

Source : JAXenter