TypeScript 3.6 Beta release, stable version scheduled to launch in late August

TypeScript 3.6 Beta has been released , the team expressed the hope that this beta version is expected to become fully functional version of TypeScript 3.6. In addition, in the next few weeks, the team is stable RC version and the version released to fix the error and continue to improve performance and stability.

By  NuGet  join the beta, or use npm be acquired:

npm install -g typescript @ beta

Let's continue to see new features in this release concern.

More rigid generator (Stricter Generators)

TypeScript 3.6 imposes stricter check of iterators and generator function (generator functions) of. In earlier versions, a user can not distinguish a generator from the yield value is returned from the producer or operator.

function* foo() {
    if (Math.random() < 0.5) yield 100;
    return "Finished!"
}

let iter = foo();
let curr = iter.next();
if (curr.done) {
    // TypeScript 3.5 and prior thought this was a 'string | number'.
    // It should know it's 'string' since 'done' was 'true'!
    curr.value
}

In addition, the generator will assume the type always yield any.

function* bar() {
    let x: { hello(): void } = yield;
    x.hello();
}

let iter = bar();
iter.next();
iter.next(123); // oops! runtime error!

To the first paragraph of the code, for example, in TypeScript 3.6, the inspector will know curr.value correct type should be string, and correct errors on the next () call in the last example. Thanks due in Iteratorand IteratorResultsome changes were introduced in the type declaration part of a new type of parameters, and TypeScript representatives called for Generatorthe type of generator.

Improved UX Around Promises

PromiseIt is one of the most common uses asynchronous data method. Unfortunately, the use of Promiseobject-oriented API usually let users confused. Therefore, for the Promisecase to be error handling, TypeScript 3.6 introduces several improvements.

For example, before it is passed to another function, Promiseforget .then()or awaitcontent is usually very common . TypeScript error message is now dedicated, and inform the user that they should probably consider using awaitkeywords.

interface User {
    name: string;
    age: number;
    location: string;
}

declare function getUserData(): Promise<User>;
declare function displayUser(user: User): void;

async function f() {
    displayUser(getUserData());
//              ~~~~~~~~~~~~~
// Argument of type 'Promise<User>' is not assignable to parameter of type 'User'.
//   ...
// Did you forget to use 'await'?
}

Future plan

TypeScript 3.6 stable release is tentatively scheduled for release in late August, the team said it would release a few weeks ago in a stable launch release candidate version.

For more updates, please see the announcement .

Guess you like

Origin www.oschina.net/news/108509/typescript-3-6-beta-released