In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
What is Typescript and what are its advantages and disadvantages? I believe many inexperienced people don't know what to do about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
JavaScript may be the de facto language of the modern web, but it has long been the language of my choice for scripting. It's interesting to code with Python, but if I had something automated, I would use node. The server-side language I chose used to be Craft, but now it's powerful, but it feels clumsy. I once naively described Node as "rampant" that met the needs of all the content I wrote. I can even write Android and iOS applications in JavaScript in many different ways.
It's not that it's the perfect tool for everything, but I've been working for me for years. I have been ironically admitting the flaws in the family's main horse network, including Gary Bernhardt's mocking "Wat?". The lightning conversation still makes me think. If you have never seen it before, please stop reading immediately and continue to watch. You can thank me later.
Lightning conversation has become my recommended reading list for front-end developers (check list or consumption list?) And Jonathan Kremer's 23rd Century JavaScript Architecture.
What is Typescript?
I assume you've heard of Typescript, but if not, try to sum it up: Typescript is a strongly typed Javascript. It adds the functionality you expect for a strongly typed language, and requires a compilation step (technically "translation") to convert Typescript to JavaScript. This is because browsers don't know Typescript. Technically, Typescript does not add any new runtime functionality, but rather adds functionality for developers.
I've heard people describe Typescript as whether he likes it or hates it, but I haven't talked to anyone who has tried and hated it. I've talked to a lot of hesitant people-I'm one of them around 2016. However, the harshest criticism I have heard of Typescript from my peers is that it is an additional learning tool. Not only the language, but also the build process. However, most modern Web applications have at least one link in their build chain reserved for JavaScript,Babel as Babel, a tool that allows newer JavaScript to run on older browsers. Adding TypeScript to this pipeline should not be rocket science, especially since Babel has supported Typescript compilation since v7.
It's not supposed to be rocket science, but it sometimes feels that way, which is one of the reasons why Typescript novices sometimes struggle to get back to JavaScript running in browsers.
Benefits
But as I said, I've never heard of anyone adopting Typescript and regretting it. The benefits far outweigh the difficulties, especially in the age of Angular CLI or Create React App-both allow you to start using new Typescript-enabled projects in minutes.
I assume you know what these benefits are, but if you don't, allow me to summarize:
The compilation step of Typescript means that you can spot problems early without having to wait for the runtime to fail.
Your IDE can now prompt you earlier in the compilation step. Imagine that your IDE will tell you when you refer to a non-existent variable or call a function with the wrong argument! A real revolution! (of course, I've been teasing because "real" programming languages have been enjoyed for years.) Editor: I don't emphasize this enough. I recently converted an old project from JavaScript to Typescript to understand the complexity of the code base I inherited from others. This is a step-by-step process, during which the team continues to provide new functionality, but we encounter sample code in which we mistakenly use third-party libraries. Maybe the API has changed, or someone has misread the document, but we have passed some configuration variables that have absolutely no effect. Typescript immediately told us that we had deleted the problematic code. Obviously, it is unnecessary and very misleading.
When new features are proposed in ECMAScript (the standard that drives JavaScript), TypeScript can adopt them as soon as possible, so that you are always at the forefront.
But in fact, the main benefit is that Typescript enables your code to describe itself in a way that JavaScript cannot. When I was the only developer on the project, JavaScript wasn't so bad because I could keep everything in mind, and I had a perfect memory, right? Mistake. Even as the only developer, the code I write is prone to amnesia. Now, when I write a normal JavaScript, I hate having to read the function definition to figure out how to use it. I don't know what it returns (if any) or what parameters it accepts. I may know the number of parameters and their names, but this is not always enough:
Function doTheThing () {let error = false; / / About a million lines of code that might cause an error return error;} function consumeTheThing () {let error = doTheThing (); if (error) {/ / What do I do with the error now?}}
That's what I mean. Is "error" a Boolean value? When I see line 2, it certainly looks like this, but what about the 1 million lines of code between the end of "doTheThing"? It can be a string, an object, or someone who knows something.
You might say that this flexibility is an asset. It may be so, but more often it is a trap that lures you into a simple way, which can cause a lot of minor frustration between you and your peers. Have you ever been in the middle of someone else's code and feel like you're in a maze? That's someone else's code. You can write "good" code in JavaScript, but few people encourage you to do so.
This is the beauty of TypeScript. This does not force you to be a good developer. But this provides you with the tools to achieve this goal.
Shortcoming
Do you have any shortcomings? Of course there is.
In the literal sense, more typing. You can break through the keyboard faster (this can be a problem for people who use butterfly keyboards). It's no big deal, but some JavaScript developers hate having to write a type with every new function or variable. You don't have to do this, but if you don't use types, why use Typescript?
Because you must compile the code, it will take some time for each update and each test run. But we're talking about it for a few seconds. The time I saved with Typescript far exceeded the time it took to compile it.
Sometimes the complexity of building a project can be a real pain. This is true-if you are not familiar with the build tool, setting up a new project can be frustrating. In the short term, my advice is to find a starter project to help you-if you are considering using those frameworks, the above Angular CLI and Create React App are very useful in this regard. For a long time? Take the time to learn the tools-tsc,Babel,WebPack and all these good things. If you are using a node, try ts-node. If you are using Mocha, try ts-mocha. There are some simple shortcuts that can help you get started.
It's kind of like my view is one-sided-I don't put too much energy into my weaknesses and strengths, and I think, for the same reason, I don't spend a lot of time on the benefits of McDonald's at every meal-the benefits are limited. I think that's it.
The future
I don't think Typescript will replace JavaScript- anytime soon. Understanding the latter is crucial to making the former work. And we won't see Typescript running natively in any browser. It is a preprocessor, just like the previous CoffeeScript. The difference between Typescript and Coffescript is that the latter is a fundamental change to the language on which it is based. Typescript is a natural evolution. This not only makes learning easier, but also makes the process of converting JavaScript projects into Typescript more tedious. First rename * .js to * .ts. Now you have the Typescript project! You can then start using language capabilities at once. I can't guarantee that it will be easy, but it will tell you something that JavaScript has never had before. When you start the next project, the Typescript compiler will wait
After reading the above, have you mastered what Typescript is and what are its advantages and disadvantages? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.