After announcing TypeScript 3.1 RC version last week, Microsoft released TypeScript 3.1 as a stable version, yesterday. This release comes with support for mapped array and tuple types, easier properties on function declarations, typesVersions for version redirects, and more.
TypeScript has a concept called ‘mapped object type’ which can generate new types out of existing ones. Instead of introducing a new concept for mapping over a tuple, mapped object types now just “do the right thing” when iterating over tuples and arrays.
This means that if you are using the existing mapped types like Partial or Required from lib.d.ts, they will now also automatically work on tuples and arrays. This change will eliminate the need to write a ton of overrides.
For any function or const declaration that’s initialized with a function, the type-checker will analyze the containing scope to track any added properties. This enables users to write canonical JavaScript code without resorting to namespace hacks.
Additionally, this approach for property declarations allows users to express common patterns like defaultProps and propTypes on React stateless function components (SFCs).
Users are always excited to use new type system features in their programs or definition files. However, for the library maintainers, this creates a difficult situation where they are forced to choose between supporting new TypeScript features and not breaking its older versions. To solve this, TypeScript 3.1 introduces a new feature called typesVersions.
When TypeScript opens a package.json file to figure out which files it needs to read, it will first look for the typesVersions field. The field will tell TypeScript to check which version of TypeScript is running. If the version in use is 3.1 or later, it figures out the path you’ve imported relative to the package and reads from the package’s ts3.1 folder.
With this new refactoring, you can now easily convert functions that return promises constructed with chains of .then() and .catch() calls to async functions that uses await.
You can get the latest version through NuGet or via npm by running:
npm install -g typescript
According to their roadmap, TypeScript 3.2 is scheduled to be released in November with strictly-typed call/bind/apply on function types.
To read the full list of updates, check their official announcement on MSDN.
TypeScript 3.0 is finally released with ‘improved errors’, editor productivity and more
I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…
Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…
Once we learn how to deploy an Ubuntu server, how to manage users, and how…
Key-takeaways: Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…
While developing a web application, or setting dynamic pages and meta tags we need to deal with…
Software architecture is one of the most discussed topics in the software industry today, and…