来源:OSCHINA 时间:2023-04-19 09:14:53
(资料图片仅供参考)
TypeScript 5.1 发布了首个 Beta 测试版。
主要变化
更智能地检查未定义返回值的函数(undefined
-Returning Functions) 旧代码
function foo() { // no return}// x = undefinedlet x = foo();
// fine - we inferred that "f1" returns "void"function f1() { // no returns}// fine - "void" doesn"t need a return statementfunction f2(): void { // no returns}// fine - "any" doesn"t need a return statementfunction 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;});
Getters 和 Setters 类型之间没有限制 JSX 元素和 JSX Tag 类型之间的解耦类型检查 命名空间的 JSX 属性 支持在 Module Resolution 中查询typeRoots
Linked Cursors for JSX Tags 对@param
JSDoc Tags自动补全 Snippet 其他优化 破坏性变更 详情查看发布公告。
下载量猛增,Eclipse 基金会报告 2023 年开源 Java 势头强劲
LLVM 16.0 发布,默认标准改为 GNU++17 每日速看