TypeScript 4.1 Adds Temporal Literal Types
Written by Kay Ewbank   
Monday, 23 November 2020

TypeScript has been updated with new checking flags, editor productivity updates, and speed improvements, alongside new features including support for temporal literal types.

TypeScript is a superset of JavaScript that adds optional static types which can be checked by the TypeScript compiler to catch common errors in your programs.

typescriptlogo

The additions to this release start with support for string literal types, which can be used to model functions and APIs that expect a set of specific strings. TypeScript 4.1's template literal string type has the same syntax as template literal strings in JavaScript, but is used in type positions. When you use it with concrete literal types, it produces a new string literal type by concatenating the contents. The developers say that

"Some of the real value comes from dynamically creating new string literals. For example, imagine a makeWatchedObject API that takes an object and produces a mostly identical object, but with a new on method to detect for changes to the properties."

Support has also been added for key Remapping in mapped Types. Mapped types can create new object types based on arbitrary keys, but  until now could only produce new object types with keys that you provided them. TypeScript 4.1 now allows you to re-map keys in mapped types with a new as clause. This will enable developers to create new keys, or filter out keys, based on the inputs.

Supper has also been added for recursive conditional types. JavaScript supports functions that can flatten and build up container types at arbitrary levels, but expressing this wasn't possible in TypeScript’s type system. TypeScript 4.1 eases some restrictions on conditional types so that they can model these patterns. In TypeScript 4.1, conditional types can now immediately reference themselves within their branches, making it easier to write recursive type aliases.

Another improvement is support for checked indexed accesses to tighten the rules for the use of accessed property that have not already been listed.

Elsewhere, TypeScript 4.1 supports React 17’s upcoming jsx and jsxs factory functions through two new options for the jsx compiler option, and adds editor Support for the JSDoc @see tag meaning developers can use functionality like go-to-definition in a dotted name following the tag.


typescriptlogo

More Information

TypeScript On NuGet

TypeScript On GitHub

Related Articles

TypeScript 3.6 Generators Get Stricter

TypeScript 3.5 Adds Smart Select 

TypeScript 3.2 Gets Stricter Checking

TypeScript 3.1 Adds Mappable Tuples

TypeScript 3.0 Adds Project References 

TypeScript Adds Unused Span Reporting

TypeScript Adds Conditional Types

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


JetBrains Updates IDEs With AI Code Completion
04/04/2024

JetBrains has launched the first set of updates for 2024 of its JetBrains IDEs. The new versions include full-line code autocompletion powered by locally run AI models.



Liberica Alpaquita Containers Now Come With CRaC
23/04/2024

Bellsoft has added CRaC support to its ready-to-use Alpaquita container images. This will enable developers to seamlessly integrate CRaC into their projects for performant Java in the Cloud.


More News

raspberry pi books

 

Comments




or email your comment to: comments@i-programmer.info