TypeScript 3.2 now available

Microsoft has announced a new update to its open-source, superset of the JavaScript programming language. TypeScript 3.2 adds a number of new features such as improved narrowing for tagged unions, error message improvements and editing enhancements.

NuGet users and Visual Studio 2015 users should be aware that with this release and future releases, the team will only be shipping a MSBuild package instead of a standalone compiler package, which will depend on an invokable version of Node.js, according to the company.

“If you’re unfamiliar with TypeScript, it’s a language that brings static type-checking to JavaScript so that you can catch issues before you even run your code – or before you even save your file. It also includes the latest JavaScript features from the ECMAScript standard on older browsers and runtimes by compiling those features into a form that they understand,” Daniel Rosenwasser, program manager of TypeScript, wrote in a post. But beyond type-checking and compiling your code, TypeScript also provides tooling in your favorite editor so that you can jump to the definition of any variable, find who’s using a given function, and automate refactorings and fixes to common problems.”

Some of the major features of this release include:

strictBindCallApply
The latest release comes with stricter checking for bind, call and apply. “In JavaScript, bind, call, and apply are methods on functions that allow us to do things like bind this and partially apply arguments, call functions with a different value for this, and call functions with an array for their arguments,” Rosenwasser wrote. “Unfortunately, in its earlier days, TypeScript lacked the power to model these functions, and bind, call, and apply were all typed to take any number of arguments and returned any. Additionally, ES2015’s arrow functions and rest/spread arguments gave us a new syntax that made it easier to express what some of these methods do – and in a more efficient way as well.”

To address this, Microsoft added parameter types from TypeScript 2.0 and modeling parameter lists with tuple types in TypeScript 2.0. These enable bind, call and apply to be abstracted accurately without hard coding, the company explained. Combined, the two create strictBindCallApply, which declare stricter versions. However, Rosenwasser explained a caveat of this is that it is not able to fully model generic functions or functions with overloads.

Object spread on generic types
While TypeScript already does a good job of supporting the copying of existing properties from existing objects into a new one known as spreads, it had trouble working with generics. Object spread type now permits spread on generics and models.

Configuration inheritance via node_modules packages
“TypeScript 3.2 now resolves tsconfig.jsons from node_modules. When using a bare path for the ‘extends’ field in tsconfig.json, TypeScript will dive into node_modules packages for us,” Rosenwasser wrote.

Object.defineProperty declarations in JavaScript
TypeScript now recognizes declarations that use Object.defineProperty, giving users better completions and stronger type-checking, Rosenwasser explained.

The release also adds support for printing the implied configuration object to the console with –showConfig and type-checking for BigInt. BigInts are an upcoming proposal for ECMAScript for modeling theoretically large integers. “TypeScript 3.2 brings type-checking for BigInts, as well as support for emitting BigInt literals when targeting esnext,” Rosenwasser wrote.

Other features include fixes to type assertions, missing new keyword, infer types from usage outside of noImplicitAny and infer JSDoc types from usage.

As far as improvements, version 3.2 addresses formatting, editing, narrowing for tagged unions, and error messages.

The team is already working on the next release of the language, which is expected to be released in January. Some things on the roadmap include partial type argument inference and improvements to scaffold out declaration files. The full roadmap is available here.

The post TypeScript 3.2 now available appeared first on SD Times.

from SD Times https://ift.tt/2Pcdpm3

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website at WordPress.com
Get started
%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close