TypeScript 4.6 RC 发布

栏目: 软件资讯 · 发布时间: 4年前

内容简介:TypeScript 4.6 首个 RC 版本已发布。 新特性概览 支持在super()前执行构造函数代码 面向 Destructured Discriminated Unions(可辨识联合类型)提供控制流分析 优化递归深度检查 (Recursion Depth Checks) 优化索...

TypeScript 4.6 首个 RC 版本已发布

新特性概览

支持在super()前执行构造函数代码

此特性允许在 super 调用前去执行没有引用 this 的代码,这是由于 JavaScript 的限制,super 前不能调用 this,TypeScript 之前出于实现的原因,规定不能执行所有代码。

示例

class Base {
    // ...
}

class Derived extends Base {
    someProperty = true;

    constructor() {
        // error!
        // have to call 'super()' first because it needs to initialize 'someProperty'.
        doSomeStuff();
        super();
    }
}

新的性能分析工具:TypeScript Trace Analyzer

TypeScript 提供了--generateTraceflag 来生成编译器在本次编译工作中的耗时占比,或者用于诊断 TypeScript 编译器的问题。虽然--generateTrace生成了有价值的信息,但在现有的跟踪可视化 工具 中阅读效果不好。

最近发布的 TypeScript Trace Analyzer 可更直观、更清晰地展示报告。详情点此查看

--target es2022

TypeScript 的--target 选项已支持es2022

这意味着像类字段 (class fields) 这样的特性现在会有一个可以保留的稳定输出 target,亦意味着可使用新的内置功能如 :at() method on ArraysObject.hasOwn 和 the cause option on new Error

延伸阅读:ECMAScript 2022 预览

对 JavaScript 文件引入更多语法检查

这是 4.6 版本的主要特性,在 TypeScript 中引入的 JavaScript 文件,现在会提示其语法错误,如重复声明、对 export 声明使用了修饰符、在 switch case 语句出现多次的 default case 等。类似于 TypeScript 文件,可通过@ts-nocheck来禁用对此文件的类型检查。

示例

const foo = 1234;
//    ~~~
// error: Cannot redeclare block-scoped variable 'foo'.

// ...

const foo = 5678;
//    ~~~
// error: Cannot redeclare block-scoped variable 'foo'.
function container() {
    export function foo() {
//  ~~~~~~
// error: Modifiers cannot appear here.

    }
}

详情查看发布公告


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Distributed Systems

Distributed Systems

Sukumar Ghosh / Chapman and Hall/CRC / 2014-7-14 / USD 119.95

Distributed Systems: An Algorithmic Approach, Second Edition provides a balanced and straightforward treatment of the underlying theory and practical applications of distributed computing. As in the p......一起来看看 《Distributed Systems》 这本书的介绍吧!

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具