You may also like: Types of web development
History of TypeScript
Release Date: October 2012
Development Side: Both client and server-side
What is TypeScript?
Features of TypeScript
- TypeScript code is useful anywhere. You can use any browser, device, or operating system can execute the TypeScript code smoothly. The code is not specific to any virtual engine or OS.
Creator: Brenden Eich (Netscape)
Release date: November 1996
Category: Standard Scripting Language
Development Side: Client-Side
- Server communication- before a page is sent to the server-side, it gives the option for validation of user input
- Faster loading speed- as the changes are done in real-time. The developers don’t have to reload the pages to observe the changes.
✦ TypeScript sample code:
var myvar = //user input
return number + 100;
The above TypeScript shows us that the result will always be a number. But what if a user inputs a character say “dog”? well in an ideal situation we alert the user that the operation is not possible! But, without that, the output will show dog100.
feeling = ’empty’;
feeling = 10;
The HTML will look like this
<input type = “textbox” id = “howyoufeel”>
and the script will be:
feeling = document.getElementById(“howyoufeel”).value;
Unless we put explicit checks in this script, JS will continue to accept any value from the user and pass it on. Hence, you can put anything like 123, @.*$%, etc. in the feeling variable.
TypeScript Pros: When to use TypeScript?
You should use TypeScript for the following benefits:
✦ Fast Error Detection
TypeScript enables IDEs and the development environment to display errors and warnings while you code. Hence, spotting errors and correcting them in the early stages will not only save your time but also minimize runtime errors.
✦ Optional Static Typing
✦ Code Optimization
If you are looking for proper code optimization then, TypeScript needs to be your first choice. This is because it offers advanced features that improve the quality and readability of the code. Further, TypeScript offers Type Annotation, Generics, Intellisense, API Documentation, Namespaces, Interfaces, and so on.
✦ Portability and Flexibility
TypeScript is a flexible, scalable, and efficient programming language.
✦ Enhanced IDE support
The IDE support for TypeScript makes a developer’s job easy than before.
Firstly, it informs developers in real-time of type information. Secondly, it highlights compiler errors that are directly visible on the screen.
Finally, TypeScript allows refactoring of code without any issues.
But what are the scenarios where TypeScript is not suitable?
✦ Complicated Typing System
✦ Compilation required
✦ Enlarged code
The enhanced code readability brought in by TypeScript along with type annotations has its own cons.
So firstly, a developer has to write more code and this evidently slows down the development process. Secondly, the developer requires some additional annotations that make TS files larger than those written in plain JS. Further, the difference in the number of lines of codes depends on a variety of factors.
In short, the downside of transpiling is that it requires an additional step before complete execution.
✦ Small Projects
Hence, JS is best suitable for small projects.
✦ Speed and Efficiency
✦ Add-on Extensions
✦ Client-side Security
Further, any random developer can place some code into the site that will compromise the security of the data over the website.
✦ Browser support
Although some HTML editors support debugging, they are not as efficient as other editors. Also, error detection is tough because the browser doesn’t show any errors. Hence, debugging in JS is hectic.
✦ Slow Bitwise Function
This continuous conversion of the Bitwise function increases the time of execution.