TypeScript has just become popular, why are the big guys starting to abandon it?

I believe that when you saw the title, you couldn't help but curse, and even wanted to criticize the editor severely... I know you are impatient, but don't be impatient yet.

via https://www.zhihu.com/question/621997070

This is actually a very popular question on Zhihu recently. According to the site's consistent tradition - "Ask first if it is true, then why" , this question seems to be sensationalizing and deliberately trying to attract attention.

You must know that TypeScript, which was released in 2012, currently ranks at the top of many programming language rankings, indices or developer surveys. It is also the most popular and commonly used programming language and is used by millions of developers around the world.

Just find a few news articles about TypeScript to get a feel for it:

Regarding the so-called "TypeScript was abandoned by the big guys", there are indeed two well-known events this year:

As for whether you are a great expert or not, you might as well take a look at  the “connotation” evaluation of front-end guru Winter:

Closer to home, let’s return to the topic itself. Open Source China recently interviewed three senior front-end engineers:

  • Liu Yong, nicknamed Tianzhu in the community, is the head of Node.js  Infra of a large company  and the core developer of EggJS / CNPM.

  • Liu Yicheng, whose community nickname is xcatliu (stray kitten), is the author of " Introduction to TypeScript Tutorial" and is from the Tencent Documentation Team. 

  • Li Zhen, nicknamed tick in the community, is from the Tencent Documentation Team.

The direction of the discussion just started from the topic of " abandoning TypeScript and returning to JavaScript ". Let's take a look at their respective views.


Q: TypeScript  is a new language based on  JavaScript  . In theory, it should be more complete than JavaScript. Why do people still go back to the old JavaScript? Does this count as reversing history?

Liu Yong: It’s not a reversal, it’s just a choice. In some scenarios, writing TypeScript will bring some additional costs. For example, I have seen the source code of some open source libraries. The core logic may only be dozens of lines. However, in order to achieve accurate type prompts, the type gymnastics written are far more than the core source code. What is right and wrong is different for different developers. The criterion needs to find the balance point. Of course, as far as the current situation is concerned, I personally recommend using TypeScript if you can, but whether you want to do type gymnastics depends on the developer's own situation.

Liu Yicheng: It is rare for projects that have already used TypeScript to switch back to using JavaScript. More projects are upgrading from JavaScript to TypeScript. TypeScript improves the JavaScript type system, making the code more maintainable, but it also increases compilation steps and some development costs. For some projects, JavaScript can already meet the needs, so there is no need to increase the complexity of the TypeScript type system. But for other complex projects, a type system is needed to help improve code maintainability, so this is not a start of history. Instead of reversing, make technical selection based on actual conditions.

 

Q: The above projects that switch from  TypeScript  back to  JavaScript  are all development frameworks, so is this related to the project type?  Are JavaScript projects more likely to be chosen for framework projects  ?

Li Zhen: Yes, the project type can be a factor that affects the choice of JavaScript or TypeScript. When developing a framework or library, especially a front-end framework or library, it is common to choose to use JavaScript.

On the one hand, development frameworks need to have broad compatibility so that developers can use them in a variety of projects. Since JavaScript is the basic language for web development, almost all browsers and environments support JavaScript. This makes it easier for frameworks written in JavaScript to be widely adopted and integrated.

On the other hand, development frameworks usually need to provide easy-to-use APIs and flexible extension mechanisms to meet the needs of various projects. Using JavaScript can express these concepts more directly without requiring too many type annotations and compilation steps. This makes it faster for developers to understand and use the framework, and easier to customize and extend.

Liu Yong: Developers of frameworks and class libraries often need to consider many edge cases. In this case, writing complete types is a very labor-intensive task, and the amount of code will be much larger, which will lead to maintenance Increase in costs. In fact, the community is still in the exploratory stage and needs to find a balance point, which parts need to be improved and which parts can be chosen.

 

Q: We started using  TypeScript  because TypeScript provides type checking, which makes up for the problem that  JavaScript  only has logic but no types. So if we use JavaScript + JSDoc to solve type declarations, do we no longer need to use TypeScript?

Liu Yong: First of all, JSDoc cannot completely solve the problem of type declaration, nor can it help developers find some problems during the development period.

Secondly, the two do not conflict. I personally also write the corresponding JSDoc when writing TypeScript, because TypeScript types cannot have more comments and descriptions. I would also like to see the TypeScript team optimize this experience in the future.

Liu Yicheng: JSDoc can only solve part of the type problems, while TypeScript is a complete type system. The TypeScript ecosystem is more prosperous. For ordinary developers and ordinary projects, the development and maintenance costs of using JSDoc may be higher than TypeScript.

Li Zhen: It is theoretically possible, but compared with TypeScript, it still has some limitations:

  • Completeness of static type checking: JSDoc annotations are annotation-based rather than directly embedded in the language, so its type checking may not be as complete and accurate as TypeScript's type system.

  • Differences in tool support: Although some tools and editors can take advantage of JSDoc annotations for type checking, their functionality and intellisense may be limited compared to TypeScript.

  • Ecosystem differences: TypeScript has an independent type system and ecosystem of type declaration files, which allows for more seamless integration with existing JavaScript libraries and tools. Using JavaScript + JSDoc may require more manual work to write and maintain type annotations.

 

Q: Some people think that the emergence of TypeScript is because ordinary people cannot control JavaScript . Some people think that "the worse people are, the more they like freedom." What do you think? Is the choice of these two languages ​​related to the level of the programmer?    

Li Zhen: It is quite boring to judge personal level by hobbies.  There are experts in writing JavaScript and TypeScript.

Liu Yong: Laugh~ It’s not uncommon for students to complain that a good TypeScript project has been submitted to a lot of Any. I have also seen many complaints about taking over a TypeScript repository and having to read a lot of type definitions to figure out how these strange types work. I think the choice of language mainly depends on the degree of engineering and standardization of the team, and too much is not enough. If a TypeScript class library writes a lot of types but doesn't even have a single test, then I think it is unqualified.

Liu Yicheng:  Part of the reason for the emergence of TypeScript is that JavaScript  is difficult to "control". JavaScript is  too flexible and lacks type constraints, making it easy to write buggy code. TypeScript solves this problem to a certain extent, making the code more maintainable. Taller.

JavaScript  and TypeScript cannot be used to measure the level of programmers. For simple projects or personal projects, JavaScript  may be more lightweight and flexible, but for complex projects that require large team collaboration, TypeScript's type system can bring better code maintainability and reliability.

 

Q: How do you see the future development of  TypeScript ? Do you think it will be a fad or will it eventually replace JavaScript ? Whose technology ecosystem do you think is better?   

Liu Yong: TypeScript  is positioned as a superset of JavaScript  , and its capabilities are based on the ECMAScript specification formulated by TC39 (i.e. JavaScript  ). I don’t think it will replace JavaScript  . After all, it is not an official specification, and  the existing ecosystem of JavaScript is too huge.

Of course, TypeScript has now become a de facto standard to some extent, especially because Node.js officials are hesitant about where ESM and CJS will go, which has led to a long-term separation among community developers, and more and more people are forced to choose to use TypeScript. Write a class library and compile it to ESM and CJS at the same time. At present, the TypeScript ecosystem has reached a large scale, so it will not be as short-lived as CoffeeScript.

Liu Yicheng: I personally think TypeScript will continue to be popular and be more widely used. But it will not "replace" JavaScript  . The goal of TypeScript has never been to "replace" JavaScript  , but  to provide  a type system based on JavaScript as a supplement to JavaScript and to play its respective advantages in different projects and scenarios.

The technical ecology of JavaScript  and TypeScript has long been integrated. Almost all libraries will have TypeScript type files.

Li Zhen: I think TypeScript is unlikely to completely replace JavaScript, but rather serves as a supplement and enhancement to JavaScript. There will not be a zero-sum game between the two for the time being, and I hope that both languages ​​can develop better. At present, the JavaScript ecosystem is larger, but TypeScript's status and influence continue to grow. As an ordinary developer, it is best to pay attention to its development when there is no conflict between the two.

 

View the full interview content: "TypeScript is not needed at all, JS + JSDoc is enough", the boss said I want more

Guess you like

Origin www.oschina.net/news/260816