typescript仅仅是为了给javascript增加类型而对java的一个仿制吗

如果是这样,我不直接学习java或者c#就好了吗?(不考虑前端编程这个因素)

或者换句话说,typescript跟java在语法语义有什么不同吗?能给编程带来什么帮助吗?

带着这个疑问,翻了一下现有的资料,找到typescript官网的一段解释,觉得有点意思,翻出来,供大家参考。

https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes-oop.html

Rethinking Types

These aspects describe a reified, nominal type system. The types we wrote in the code are present at runtime, and the types are related via their declarations, not their structures.

TypeScript provides a number of mechanisms to work with types in a set-theoretic way, and you’ll find them more intuitive if you think of types as sets.

简单讲,typescript将类型看做集合们。这个思想可以说总算回归到正义了。

 

其他的没有看懂,鸭子类型的实现似乎太宽泛了。

另外,由于编译过程中将类型信息抛弃了,造成运行时类型反射没法进行,不能不说是一个遗憾。

 

posted @ 2024-05-02 15:36  高树岭软件实验室  阅读(10)  评论(0编辑  收藏  举报