TypeScript 5.1 Beta 发布

软件资讯 软件资讯 发布于 2年前 26 浏览 0 回复

TypeScript 5.1 发布了首个 Beta 测试版。

主要变化

旧代码

function foo() {
    // no return
}

// x = undefined
let x = foo();
//  fine - we inferred that 'f1' returns 'void'
function f1() {
    // no returns
}

//  fine - 'void' doesn't need a return statement
function f2(): void {
    // no returns
}

//  fine - 'any' doesn't need a return statement
function f3(): any {
    // no returns
}

//  error!
// A function whose declared type is neither 'void' nor 'any' must return a value.
function f4(): undefined {
    // no returns
}

新代码

//  Works in TypeScript 5.1!
function f4(): undefined {
    // no returns
}

//  Works in TypeScript 5.1!
takesFunction((): undefined => {
    // no returns
});
//  Works in TypeScript 5.1!
takesFunction(function f() {
    //                 ^ return type is undefined

    // no returns
});

//  Works in TypeScript 5.1!
takesFunction(function f() {
    //                 ^ return type is undefined

    return;
});

详情查看发布公告



为您推荐相关文章:

  • TypeScript 5.0 发布首个 RC 版本
  • TypeScript 5.0 发布
  • TypeScript 5.3 RC 发布
  • TypeScript 5.3 Beta
  • TypeScript 5.2 正式发布
  • 同类文章推荐:

  • Apache bRPC 1.11.0 发布
  • VirtualBox 7.1.4 发布
  • Python 3.14.0 Alpha 1 发布
  • Elasticsearch 8.15.3 发布
  • Spring Data 2024.1.0 RC1 发布
  • DBeaver 24.2.3 发布