TypeScript 3.5 Features : Let’s Check What’s New in the Bag

Team TypeScript released of TypeScript 3.5 in the market a few times back in May 2019. TypeScript is a superset of JavaScript which is a popular programming language in the market today. The release announcement comes with a new Omit type and type checking performance improvements along with others.

So let’s check them out what’s new in detail…

Latest Features of TypeScript 3.5

The ‘Omit’ helper type

Most of the time, users create objects wherein certain properties get omitted. A new version of Omit has been defined with the release of TypeScript 3.5. You can easily use this anywhere as it comes with its own lib.d.ts. In order to express types created through object rest, the compiler makes use of this ‘Omit’ type all the while removing the structure on generics.

Speed improvements

Since its past release, team TypeScript has been trying to remove certain functionality all the while working on to improve certain code paths. This way for a number of incremental checks, TypeScript 3.5 has been observed to be comparatively faster than TypeScript 3.3. When we compare the compile-time, TypeScript 3.5 has been said to have fallen compared to 3.4. It has to be understood that any of the editor operations and code completion can take place quickly. Moreover, using TypeScript 3.5, the amount of rebuilding time has been decreased to a level of 68%, when compared with its earlier version. The compiler settings also include here different optimizations like where the files were found, why were the files looked for, etc.

The –allowUmdGlobalAccess flag

It is now possible to reference UMD global declarations like export with TypeScript 3.5 as namespace foo. You can do this from anywhere which includes modules and for the same, you can make use of allowUmdGlobalAccess flag.

Union types having improved excess property checks

The object literals in TypeScript come with excess property checking. It has been seen that in case of earlier versions of TypeScript, the object literal contained certain excess properties, but when it comes to matching the Label and Point, it failed.

Generic constructors offering higher-order type inference

newFn has been allowed to be generic in TypeScript 3.4. Also, to make it work along with constructor functions properly, its behavior has been generalized in case of TypeScript 3.5. This means that the functions within certain UI libraries like React operate on class components than they are more capable of working on generic class components.

Union type checking is smarter

In the case of TypeScript, each constituent type is compared in isolation, when checking against other union types. It checks to look at whether the type of source can be assigned to the target when trying the assign a source to it. TypeScript 3.5 changes this. Here when you are assigning types to T like discriminant properties, TypeScript goes ahead and into the union of different inhabitant type, it decomposes types which are like S.

TypeScript 3.5 also includes new editing tools

Extract to type aliases

A new refactoring is now supported by TypeScript 3.5, and this is used to extract types for local type aliases. Still, you will find issues in case of users who like interfaces in place of type aliases and have to extract object types for the interfaces too.

Smart Select

In order to expand text selections in a syntactical manner even further, it offers the editors with API. Any editor which can properly query the language server of TypeScript has this feature made available. Moreover, it is cross-platform in nature.

TypeScript 3.5 comes with some breaking changes

TypeScript 3.5 comes with some evident differences. Let’s see them below:

Union types come with improved excess checks

When it comes to excess property checks in union types, TypeScript 3.5 is strict.

It helps with:

  • Adding a type of assertion over the objects
  • In order to signal unspecified properties which are expected, it adds an index signature to the expected type.

Lib.d.ts comes with Omit helper type

A new Omit helper type comes with TypeScript 3.5. This means an error message will be displayed to any project where any global declarations will include Omit in it.

Unknown is implicitly constrained by generic type parameters

This change comes with TypeScript 3.5 while previously there was just an empty object type {} for the implicit constraint of type parameters. When we put to use, unknown and {} are almost the same but, they come with specific differences.

  • Unknown is not assignable to objects but {} is.
  • Unknown can be undefined or null but, {} is not considered either of it.
  • Even though {} is implicit which comes under noImplicitAny as any error, it can be indexed with a string (k[“foo”])

Primitives in ES5 are rejected by Object.keys

In case the Object.keys is passed through any non-object argument, then it throws an exception in case of ECMAScript 5 environments. If the target is ES5 in case of TypeScript 3.5, the called Object.keys should pass a valid object. The change in generic inference interacts with a change from {} to unknown.

{[K: string]: unknown} is not considered as wildcard assignment target anymore

TypeScript 3.5 has removed this rule. The change from {} to unknown in the absence of generic inference was the reason for this change. You can even find a number of alternatives based on the expected behavior of this rule and they are:

  • unknown
  • {[s: string]: any}
  • object
  • any
  • {[s: string]: {}}

Get Ready to Welcome TypeScript 3.6 Soon

You have plenty of new things such as upgrades and improvements in the recently released TypeScript 3.6 such as Stricter Generators, More Accurate Array Spread, Improved UX and much more. Stay tuned to our blog to get all latest updates.

Looking to Hire
Professional JavaScript Developers?

Check In & Save Big Bucks

Need Consultation?

Put down your query here...

    Saurabh Barot

    Saurabh Barot, the CTO of Aglowid IT Solutions, leads a team of 50+ IT experts across various domains. He excels in web, mobile, IoT, AI/ML, and emerging tech. Saurabh's technical prowess is underscored by his contributions to Agile, Scrum, and Sprint-based milestones. His guidance as a CTO ensures remote teams achieve project success with precision and technical excellence.

    Related Posts