Info Tech Jesi – The Best Tech Website – Check Out the Latest Trends!
Tech

TypeScript 4.8 update – what’s new?

TypeScript 4.8 is the third functional release this year of a superset of statically typed JavaScript. It adds several improvements, and there are a few critical changes to be aware of before the update.

The release also contains some optimizations for compilation. “tsc” with the –build, –watch, and –incremental command line parameters. Among other things, the compiler reuses existing information and does not update timestamps for unchanged areas in watch mode. If you wish to read some basic information about TypeScript, check this post.

Unknown, null, or undefined?

Some changes concern strict null checks for projects with strictNullChecks. The simplification concerns the type introduced in version 3.0. “unknown” is a safe alternative to the “any.” Previously, you could not assign a variable of a different type without checking, and vice versa. The “unknown” declared variable is assignable. Recently, however, assigning a variable of type {} | null | undefined is allowed because it likes “unknown,” “null,” “undefined,” and any other type of object.

For TypeScript control flow analysis, the “unknown” type is now similar to the union type above. It changes the type check with if(x).

In addition, the current version simplifies the definition of NonNullable-Generics, which are now just the intersection of target type and {}: type NonNullable<T> = T & {};.

Another check targets unconstrained generics, which have recently been included in projects. strictNullChecks should no longer be passed to functions that expect non-null values.

The same is not the same

A small change applies to comparing objects with array literals. JavaScript does not check the contents for equality, but it does check if the reference links to the same instance. In Python, a query in the form if mein_array == [] checks if the array is empty. The comparison between JavaScript and TypeScript always ends in an error.

Other JavaScript syntax errors and bindings

TypeScript now displays more standard JavaScript syntax and binding errors. They are shown at compile time and when opening files in an editor with the TypeScript extension installed for Visual Studio, Visual Studio Code, or Sublime Text.

Repeated const statements, misuse of keywords, and area errors will now be detected by TypeScript, giving you immediate feedback at runtime.

This addition is a critical change, as the source files must now contain grammatically correct JavaScript. Previously, the TypeScript compiler ignored most JavaScript syntax errors. You should use a comment to disable this feature if you think your codebase will be incompatible with this enforcement.

Another critical change

A second critical change in this update – object rest expressions now remove non-extensible elements from shared objects. It improves consistency when destructuring ungeneralized types but means that your existing variables may not have some of the properties they had in TypeScript 4.7.

Summary

TypeScript 4.8 has improved type inference, working with the class constructor, and added ES2022 as a supported output target. TypeScript has found a solution to the problem of comparing “infinitely” nested types. In version 4.8, it learned to distinguish between such situations and check for “infinite” nesting. While in version 4.7, it did not allow comparing two variables since TypeScript checked nesting only up to a certain level. Among others, there are also several critical changes in improved JavaScript syntax error detection and removal of non-extensible expression members of object remnants.

TypeScript has been gaining popularity lately, thanks to the proliferation of Angular2. Many people would like to try TypeScript but don’t have the ability or even willingness to spend time figuring out how to configure it. As we see, developers try to fix this problem with every update. So, it is a perfect time to start.

Related posts

Significant Areas of Study at Tennessee Technology Community at Nashville

György Taki

Help Business Dexterity and Income Development With Technology Rethinking Arrangements

György Taki

The Parent-Student Relationship In College Searches

György Taki