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. 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. 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 .
More Information Related ArticlesTypeScript 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.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.
Comments
or email your comment to: comments@i-programmer.info
<ASIN:1871962579> <ASIN:1871962560> |
|||
Last Updated ( Friday, 30 November 2018 ) |