TypeScript Improves Never-Initialized Variables Checks
Written by Ian Elliot   
Monday, 21 October 2024

Microsoft has announced TypeScript 5.7 in beta, with improvements including stronger checks for variables that have never been initialized before use, and path rewriting for relative paths.

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. TypeScript can use this information to help you avoid about mistakes like typos, missing arguments, or forgetting to check for null and undefined.


The first improvement to TypeScript 5.7 is in the checks for variables that haven't been initialized. TypeScript has long-standing support for catching issues when a variable has not yet been initialized in all prior branches. However, until now there have been some places where this has failed. For example, if the variable is accessed in a separate function, the type system doesn’t know when the function will be called, so assumes that the variable will be initialized. The checks have been tightened in this version, so that although TypeScript 5.7 will still give some leeway on variables that could have been initialized, the type system is able to report errors when variables haven't ever been initialized.

The second improvement is a change to deal with tools that support the running of TypeScript code "in-place", meaning they do not require a build step to generate output JavaScript files. The blog post explaining the improvement mentions ts-node, tsx, Deno, Bun, and Node.js. A problem can arise if developers want to generate .js files out of .ts files created like this, because the import path is relative but the output path needs to be absolute, and until now TypeScript has avoided rewriting any paths. There's now a new compiler option that will rewrite the path to be absolute.

Other improvements include support for --target es2024, which allows users to target ECMAScript 2024 runtimes; faster Project ownership checks in editors for composite projects; and validated JSON imports when importing from a .json file under --module nodenext so TypeScript will now enforce certain rules to prevent runtime errors.

TypeScript 5.7 is available in beta now.

More Information

TypeScript On NuGet

TypeScript On GitHub

Related Articles

TypeScript 5.6 Tightens Truthy And Nullish Checks

TypeScript 5.5 Adds ECMAScript Set Support

Node.js Adds Experimental TypeScript Support

TypeScript 5 - Smaller, Simpler, Faster

TypeScript 4.7 Adds Node.js ECMAScript Module Support

TypeScript 4.6 Improves Constructors

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


Gifts For Geeks 2024
22/11/2024

Are you ready for Thanksgiving, when overeating remorse and a surfeit of being thankful causes the unsettling thought that there are only four weeks till the Xmas break? So here is a mix of weird [ ... ]



Discover PostgreSQL How-Tos
16/12/2024

A veritable treasure trove of assorted how-to recipes for PostgreSQL, stored as a Github repository, has been started by Nikolay Samokhvalov, well known in the PostgreSQL world.


More News

espbook

 

Comments




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

Last Updated ( Monday, 21 October 2024 )