TypeScript 3.2 Gets Stricter Checking
Written by Ian Elliot   
Friday, 30 November 2018

There's a new version of TypeScript that has tightened up type-checking for methods on functions, and added a way to handle spreads of existing objects into new objects.

TypeScript is the superset of JavaScript developed by Microsoft. The idea behind it is to add static type-checking to JavaScript so that you can catch issues before you even run your code.

TypeScript builds on the ECMAScript standard and includes support for optional static types that are designed to make it easier to use when creating large client or server-side applications. Once created, your TypeScript code then gets transformed into clean, runnable JavaScript. TypeScript includes editor support for Visual Studio 2015 and 2017, Sublime Text 3 and Visual Studio Code.

typescriptlogo

One of the changes to this new version is stricter checking for bind, call and apply. These are methods on functions, and until now TypeScript hasn't been able to model the functions. Bind, call and apply were therefore designed to take any number of arguments and to return any. ES2015’s arrow functions and rest/spread arguments have made it easier to express what some of the methods do, but the developers of TypeScript have reworked the implementation so that it uses modeling parameter lists with tuple types, and that TypeScript's uses of bind, call and apply can be more strictly checked if you choose to use a new flag called strictBindCallApply.

Another improvement to this version is the way TypeScript handles spreads of existing objects into new objects. You can spread an object to copy its existing properties, but until now TypeScript needed to know quite a lot about the type, meaning it wouldn't work with generics. The TypeScript developers had been attempting to come up with a general rule for handling spreads, but it was very complicated. However, a more pragmatic approach has been used based on intersections. This works for most uses of spreads in JavaScript, where users can model the behavior with intersection types (i.e. Foo & Bar). There's also Object.assign, which is a function that exhibits most of the behavior of spreading objects. This is already modeled using intersection types, and the TypeScript developers say they've seen very little negative feedback around that.

In view of all this, TypeScript 3.2 now permits object spreads on generics and models them using intersections.

Other improvements in this release include configuration inheritance via node_modules packages; and a new primitive type called the bigint. ECMAScript has a proposal to add bigInts to provide a way to model theoretically arbitrarily large integers.

.

typescriptlogo

 

More Information

TypeScript On NuGet

TypeScript On GitHub

Related Articles

TypeScript 3.1 Adds Mappable Tuples

TypeScript 3.0 Adds Project References

TypeScript Adds Unused Span Reporting

TypeScript Adds Conditional Types

TypeScript 2.7 Improves Type Inference

TypeScript 2.5 Adds Optional Catch Binding

TypeScript 2.4 Adds Dynamic Import Expressions  

TypeScript 2.3 Released

TypeScript 2.2 Adds More Code Actions

 

 

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


Rare Computer History Memorabilia Being Auctioned By Bonhams
23/10/2024

Invitations handwritten and signed by Charles Babbage, seminal papers by  Alan Turing and Claude Shannon, a "Blue Box" phone hacking device, a prototype Apple Macintosh and an Apple Lisa 2/10 are [ ... ]



Edera Releases Open Source Container Benchmark And Scanner
07/11/2024

Edera has released Am I Isolated, an open source container security benchmark that probes users runtime environments and tests for container isolation.


More News

espbook

 

Comments




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

 

<ASIN:1871962579>

<ASIN:1871962560>

Last Updated ( Friday, 30 November 2018 )