How does TypeScript declare types reasonably and efficiently?

problem description

I recently used TypeScript in my project and found that I need to write a lot of type declarations. If a variable is passed between several files, the type should be declared everywhere, and a large number of type declarations lead to a great reduction in efficiency. How to balance the time of business code and type code? Where are the efficiency gains and benefits of writing types reflected?

the environmental background of the problems and what methods you have tried

I put all the types under the types folder. If a variable appears in different files, import the corresponding type directly to achieve reuse, but I still don"t know how to balance the time of writing business code and type code. Finally, in order to rush to work, I have to write any everywhere, feeling that I have lost the meaning of using ts.


declares the type for readability. If you don't need to read it for the time being, you can add


later. The type of

entity (corresponding to entity such as person / thing, or virtual entity such as order / order parameter, noun) should precede "operation" (CRUD, verb). It is better to write this part at some time and then use it everywhere.

the improvement of efficiency is reflected in that if there is a type mismatch, there will be mistakes everywhere, and when the type is changed everywhere, the behavior is also right by the way

.

I think the reuse of interface and class is quite easy to use. Just refer to it in a specific place, which is consistent with a common function and so on.
and the hints of static properties it provides can also improve some efficiency. after all, even if you write your own code in a few days, you don't know what properties are on an object.
the most important thing is that it is really friendly to newcomers or other people who take over. After all, there are not only a few people working in a company.

personally, I feel that it takes less time, and the maintainability provided is very high.


I usually have a global.d.ts under the project src directory to uniformly declare the type


tsconfig opens the implicit any and makes full use of letting typescript guess the type himself.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b30697-2b48c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b30697-2b48c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?