In Focus

TypeScript 3.0 Announced

Recently, Microsoft has announced TypeScript 3.0. It is an extension of JavaScript aiming to bring static types to modern JavaScript.

Recently, Microsoft has announced TypeScript 3.0. It is an extension of JavaScript aiming to bring static types to modern JavaScript.
The compiler of the TypeScript reads in TypeScript code including things like type declarations and type annotations and emits clean readable JavaScript with those constructs transformed and removed.
Like your favorite browsers and Node.js, the code runs in any ECMAScript runtime.
To learn more about TypeScript you can go to the official website and you can try the latest version of TypeScript 3.0 through NuGet.
The company has also shared a list of updates- 
  • Project references
    • --build mode
    • Controlling output structure
    • Further work
  • Extracting and spreading parameter lists with tuples
  • Richer tuple types
  • The unknown type
  • Improved errors and UX
    • Related error spans
    • Improved messages and elaboration
  • Support for defaultProps in JSX
  • /// <reference lib="..." /> directives
  • Editor Productivity
    • Named import refactorings
    • Closing JSX tag completions and outlining spans
    • Quick fixes for unreachable code and unused labels
  • Breaking changes
    • unknown is a reserved type name
    • API breaking changes
Project references
Project references allow the dependency of TypeScript projects over other TypeScript projects specifically allowing the tsconfig.json files to reference other tsconfig.json files.
The company states that “One of the biggest features that we’ve worked on for TypeScript 3.0 is called “project references”, and it aims to make working with these scenarios easier.”
Extracting and spreading parameter lists with tuples
TypeScript 3.0 now allows to better model scenarios by allowing rest parameters to be generic, and inferring those generics as tuple types! Instead of declaring each of these overloads.
Richer tuple types
To make tuples model parameter lists, we had to rethink tuple types a bit. Before TypeScript 3.0, the best that tuples could model was the order and count of a set of parameters. However, parameter lists aren’t just ordered lists of types.
The unknown type
Any type is the most-capable type in TypeScript – while it encompasses the type of every possible value, it doesn’t force us to do any checking before we try to call, construct, or access properties on these values. It also lets us assign values of type any to values that expect any other type.
Improved errors and UX
In TypeScript 3.0 error messages can provide messages on other locations enabling users to reason about cause and effect of an error.
Source: Microsoft
TypeScript 3.0 will now be providing the shorter and clearer error messages.
Source: Microsoft
Support for defaultProps in JSX
If you’ve ever used default initializers in modern TypeScript/JavaScript, you might know how handy they can be for function callers. They give us a useful syntax to let callers use functions more easily by not requiring certain arguments while letting function authors ensure that their values are always defined in a clean way.
/// <reference lib="..." /> directives
polyfills are one of the issues in the community. Libraries providing newer APIs in older runtimes have often their own declaration files.
The company states “While this is sometimes fine, these declarations are global, and may provide issues with TypeScript’s built-in lib.d.ts depending on users’ compiler options like --lib and --target. For example, declarations for core-js might conflict with the built-in lib.es2015.d.ts.”
TypeScript 3.0 provides a new way of file declaration in the built-in APIs as /// <reference lib="..." />.
Editor Productivity
TypeScript leverages its syntactic and semantic knowledge to provide services for writing code more easily. It also acts as an engine for TypeScript and JavaScript for editors including Visual Studio, Visual Studio Code, and editors with a TypeScript plugin.
Breaking changes
The company states “We expect TypeScript 3.0 to have very few impactful breaking changes. Language changes should be minimally disruptive, and most breaks in our APIs are oriented around removing already-deprecated functions.”
You can get the complete roadmap of TypeScript on GitHub.
The company has also thanked their users for sharing their feedback and has also promised to bring more value to the type system and tooling experience, polishing the existing work on project references, and making TypeScript (both the language and the project) more approachable.
To learn more, you can go through the official blog.