TypeScript 5.1 Beta 发布

软件资讯 软件资讯 发布于 1年前 21 浏览 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.1 正式发布
  • TypeScript 5.2 正式发布
  • TypeScript 5.1 RC
  • 同类文章推荐:

  • FileZilla Server 1.8.2 发布,开源 FTP 服务器
  • gRPC 1.63.0 发布,跨语言 RPC 框架
  • React 18.3.0 发布
  • PHP 获得来自 STF 的 20 万欧元投资
  • Node.js v22 正式发布
  • Ubuntu 24.04 LTS 正式发布