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


GitHub Copilot Adds VSCode Agent Mode
14/04/2025

GitHub has released an agent mode and MCP support for VS Code, along with a new GitHub Copilot Pro+ plan with premium requests, the general availability of models from Anthropic, Google, and OpenAI, n [ ... ]



The End Of The App Store
07/05/2025

It could just be that Apple has made a big mistake and the longed for, or dreaded, dissolution of the App Store is upon us at last. Of course, Apple is appealing, but things don't look good for its po [ ... ]


More News

espbook

 

Comments




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

Last Updated ( Monday, 21 October 2024 )