News

What's New in TypeScript 2.8 RC

Microsoft is seeking developer feedback for the new TypeScript 2.8 release candidate, featuring new conditional types and more.

TypeScript was deemed a popular programming language in Stack Overflow's big developer survey and the most recent RedMonk language popularity report. It's an open source language backed by Microsoft that provides optional static typing while remaining a strict syntactical superset of JavaScript.

In highlighting the new features of TypeScript 2.8 RC, Microsoft's Daniel Rosenwasser introduced a new construct called conditional types.

"Conditional types help model simple choices made over based on types at runtime, but afford significantly more expressive constructs at design-time," Rosenwasser said. "Conditional types also provide us with a new way to infer types from the types we compare against using the new infer keyword which introduces a new type variable."

Other highlights were described by Rosenwasser thusly:

  • JSX pragmas: TypeScript now lets developers provide a pragma in order to specify the source of a JSX factory within any file.
  • Granular control on mapped type modifiers: "TypeScript 2.8 allows more explicit syntax for adding and removing modifiers in mapped types with the + and - operators." Previously, he said, mapped types could only add such modifiers if they already existed, which resulted in limitations when working with homomorphic mapped types -- copying all modifiers from the original type.
  • JSX.Element is resolved via the JSX Factory: This can shorten lookups for certain JSX types, such as a component. Where previously this lookup examined the global JSX namespace first, now the compiler will first attempt to search the JSX namespace where a JSX factory is located. "For example, if your JSX factory is React.createElement, TypeScript will try to first resolve React.JSX.Element, and then resolve JSX.Element within the current scope."

You can read more details about the above, along with some other new features, breaking changes and more in Rosenwasser's post, published yesterday (March 15).

Future changes for the language can be found in the roadmap, which includes a tweeted proposal maintaining that "TypeScript error messages should always come in haiku form."

[Click on image for larger view.] "TypeScript error messages should always come in haiku form." (source: Twitter).

Other features planned include:

About the Author

David Ramel is an editor and writer for Converge360.

comments powered by Disqus

Featured

Subscribe on YouTube