Summary of front-end projects - why use typescript?

typescript. It is said on the Internet that it is a superset of JavaScript, which means that it contains JavaScript, but I think typescript is more to provide us with an idea. If the front-end students have done the back-end before, then he will definitely think that typescript is very important. Great, because it provides a set of strongly typed specifications, but for traditional weakly typed js, whether this goes against the original intention of js, I don't know the answer.

So I'm only objectively speaking from the user's point of view.

1. When we refactored the project, we found that thanks to the use of typescript, haha, take a small chestnut, such as the type of a field, we defined it as a number type at the beginning of the project, and then suddenly the back-end classmates told us that it could not be done. , all have to be replaced by strings, but it is impossible for us to use the black technology String(). As a rigorous programmer, I need to change his type. At this time, the powerful strong type of typescript is checked by the compiler. A bunch of errors were reported, and we just need to change the corresponding parameters according to the errors reported. This is a little bonus.

2. There is a new person in the project. I don't have to keep explaining to him what this method is used for, what this parameter means, and which properties and methods of this object can be used. Because we have defined the interface or class at the beginning of the project. The role of each entity is clear at a glance. When we are coding in the editor, the prompt will also take the initiative to follow. This is also a benefit.

3. If you have read the source code of antd, you must know that antd also uses typescript. It does not mean that the big cows use it. We should follow the trend. What I want to say is that if you also want to make your own sdk similar to antd, then using typescript is really suitable for you, because you can define a set of canonical interfaces. It looks cool on its own, and it is also cool for users to use.

With all that said, why should I use typescript? 1. Better module management 2. Tighter type checking 3. It makes my development rigorous and free.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325914227&siteId=291194637
Recommended