TypeScript 3.7 Release Candidate appeared with Optional Chaining

Alex Alex 25 October 2019
TypeScript 3.7 Release Candidate appeared with Optional Chaining

The Release Candidate of TypeScript 3.7 is ready. Some new Features were introduced, among other things, Optional Chaining, as well as extended Support for functions, the never output. Also, Breaking Changes are back on Board.

TypeScript 3.7 RC is here. As in the past, to change between the Release Candidate and the final Release nothing, apart from critical bug fixes. Daniel rose water, Program Manager for TypeScript, presented key Features in a blog entry.

The RC can be via NuGet, via npm command npm install [email protected] or in Visual Studio 2017/2019 related. In addition, it can also be used in the VS Code or Sublime Text.

Optional Chaining

Optional Chaining allows you to Write Code that stops the Running of some of the expressions immediately, if null or undefined occurs. The Feature is in high demand: On GitHub the TC39 has reached the Proposal of 4,400 star. It is located in ECMAScript in Stage 3, what, according to its own statement, the TypeScript Team was very heavily involved. With the Release Candidate the Feature is implemented in TypeScript 3.7. Especially the Operator ?. is in the spotlight, the Daniel rose water is shown in the following example:

let x = foo?.bar.baz();

it is Hereby expressed that foo.bar.baz() is calculated, if foo is defined. The foo but null or undefined, the execution is stopped, and undefined output.

The above Code Snippet is equivalent to this:

let x = (foo === null || foo === undefined) ? undefined : foo.bar.baz();

If the bar is either null, or undefined, will generate the Code to continue the call to baz is an Error. The baz is either null or undefined, an Error also occurs. ?. does not examine only whether the left's underlying value is null or undefined, however the following properties. It should also be noted that ?. not identical to &&operations will behave in their place, it is expected to be used often will be.

IT Security Summit 2019

Secure Logins are easy!

with Arne Blankerts (thePHP.cc)

Hands-on workshop – Hansel & Gretel do TLS

Marcus Bointon (synchro media Limited)

More Features and Breaking Changes

In the new Release Candidate of TypeScript 3.7, there is extended Support for functions, the never output, so a return is not according to Failure Functions are necessary.

As an example, it was first shown to the previous method:

function dispatch(x: string | number): SomeType { if (typeof x === "string") { return doThingWithString(x); } else if (typeof x === "number") { return doThingWithNumber(x); } return process.exit(1); }

And then the new method in TypeScript 3.7 RC:

function dispatch(x: string | number): SomeType { if (typeof x === "string") { return doThingWithString(x); } else if (typeof x === "number") { return doThingWithNumber(x); } process.exit(1); }

in addition, another budding has ECMAScript Feature in the RC to enter the Nullish Coalescing Operator, associated with Optional Chaining on hold:. Also Assertion Signatures for the Model of Assertion Functions, as well as additional recursive Alias Types are new.

one of the Breaking Changes, an Update of the types of lib.dom.d.ts, and an Error output, if any of the functions within the If Statement-conditions do not seem to be called. Also, a previously existing Bug has been fixed, which now leads to local and imported type declarations generate a conflict.

All further Details TypeScript 3.7 Release Candidate Daniel rose water provides in the blog entry.

Source: entwickler.de

Comments (0)

    No comments yet

You must be logged in to comment.