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.
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."
Other features planned include:
David Ramel is an editor and writer for Converge360.