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 正式发布
  • 同类文章推荐:

  • cURL 8.15.0 版本发布
  • OpenAI 发布 ChatGPT agent
  • 谷歌高管澄清 Chrome OS 合并到 Android 的报道
  • Apache Maven 3.9.11 发布
  • VirtualBox 7.1.12 发布
  • Cloudflare 1.1.1.1 出现严重故障