TypeScript 4.0 improves type inference and now allows to correctly type functions dealing with tuples. First of all, it now supports generics when defining tuple types, allowing to use generic types defined on a function for tuple elements.
TypeScript 3.9 has been released last month, and the first beta of TypeScript 4.0 is already in beta!
I’ll only cover the language features. I might write additional posts to cover what’s also coming regarding editor productivity, performance and bug fixes.
Please keep in mind that this is article is based on beta release notes and a roadmap, it doesn’t mean that everything will actually be part of the final release as is.
Currently, when tsc is configured in
noImplicitAny mode, the following TS code doesn’t compile:
Now that this PR has been merged and thus, as of TS 4.0, the code above will compile and TypeScript will infer the type of
x to be
string | boolean.
This is one more case where TypeScript’s type inference will help us out!
This article is not just about Builder Pattern in JS/TS, I will be explaining my thought process behind it and see if you can relate yourself to this. I believe everybody has a unique way of solving problems, hope you get something to learn from it.