Typescript 在语法方面与 es6 / es7 有多少不同

How much Typescript is syntax wise different than es6 / es7

Typescript 在语法方面与 es6 / es7 有多少不同。 我们在 Typescript 中有这样的代码:

class demo {
    demoProp:any;
    constructor () {
        //...
    }
}

但是es6不需要属性之后的:any声明吗? 所以我应该继续使用 Typescript 还是应该直接学习 es6 因为它是标准的 JavaScript。 注意:- 我知道 TypeScript 据说是基于类型的,也是 es6 的超集。但是 ecma script 在不久的将来或在其下一个版本 78

中可能会是 TypeScript

在 TypeScript 中,您有类型、访问修饰符和属性:

class demo {
    public demoProp: any;
    constructor(demoProp:any) {
        this.demoProp = demoProp;
    }
}

您还可以拥有泛型类型和接口:

interface Demo<T> {
    demoProp: T
}

class demo<T> implements Demo<T> {
    public demoProp: T;
    constructor(demoProp: T) {
        this.demoProp = demoProp;
    }
}

泛型和接口在 ES6 中不可用,因为它们只有在你有类型时才有意义。

在 ES6 中,您没有属性、类型或访问修饰符:

class demo {
    constructor(demoProp) {
        this.demoProp = demoProp;
    }
}

我会学习 TypeScript,因为差异不大,如果你学习 TypeScript,你也会知道 ES6,所以你将同时学习两种语言。

关于 JavaScript 成为 TypeScript 是 not likely but is not impossible