BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News TypeScript 2.0 Released

TypeScript 2.0 Released

Bookmarks

Microsoft has released TypeScript 2.0, with Simplified Declaration File Acquisition, Non-nullable Types and Readonly modifiers.

Daniel Rosenwasser, program manager for TypeScript, said the team was "thrilled" by the release that delivers "close ECMAScript spec alignment, wide support for JavaScript libraries and tools, and a language service that powers a first class editing experience in all major editors."

TypeScript 2.0 makes it easier for developers to get and use declaration files. Rosenwasser admits that "learning how to acquire and manage declaration file dependencies" has been a major pain point for users in the past, but that with 2.0 the command npm install --save @types/lodash installs the scoped package @types/lodash, that TypeScript 2.0 automatically references when importing lodash anywhere in the developer's program.

Also new in the 2.0 release is the introduction of non-nullable Types. While the language originally intended that types were always nullable, in practice the team admits this didn’t provide protection from null/undefined issues. This contrasts with the new release, where null and undefined have their own types, allowing developers to explicitly express when null/undefined values are acceptable. This is demonstrated below, in the video courtesy of TypeScript.

Properties in TypeScript 2.0 can be declared as read-only, where any get-accessor without a set-accessor is now considered read-only.

class Person {
    readonly name: string;

    constructor(name: string) {
        if (name.length < 1) {
            throw new Error("Empty name!");
        }

        this.name = name;
    }
}

// Error! 'name' is read-only.
new Person("Daniel").name = "Dan";

The community's response to Microsoft's release was one largely of support. On HackerNews, Ed Rochenski commented:

I can't wait to use some of the new features in our production apps. Typescript is/was my bridge into javascript development, because IMHO javascript was a broken language for a long time, and I am not sure if I could have ever done as much as I have without its existence.

Non-nullable types, tagged union types, and easy declaration file acquisition are definitely the biggest wins for me with this release.

On Rosenwasser's post, user Allen left a comment to ask "I would love to use strictNullChecks on our codebase, but is there some way to tell it to go back to lax null checking for some/all library type definitions?", explaining that he had an issue using strictNullChecks with external type definitions, because the type definitions of the libraries in use were not strict null safe.

Rosenwasser replied "Right now your dependencies will need to be authored for strictNullChecks; much of the time 3rd party .d.ts files will still work regardless, but if not, feel free to send a PR to DefinitelyTyped on the types-2.0 branch."

Among the festures on the roadmap for TypeScript is support for ES8 object property spread and rest, along with decorators for function expressions/arrow functions, and support for node register hook. Full details of improvements and changes in TypeScript 1.8 can be found on the project's GitHub here.

TypeScript is open source and released via an Apache licence. InfoQ readers interested to contribute to the project should visit https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • Good news. Will wait Dart 2.0.

    by Andrew Mezoni,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    I cannot understand only one thing - Google announced that Dart 2.0 should be released at beginning of 2016 but already soon the end of 2016 and Dart 2.0 still was not released.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT