Islam Saiful
Islam Saiful
Md Saiful Islam
BACHELOR’S THESIS
May 2023
Degree Programme
Software Engineering
ABSTRACT
Tampereen ammattikorkeakoulu
Tampere University of Applied Sciences
Software Engineering
Md Saiful Islam
JavaScript alternative (Typescript) and its effectiveness in web development
Bachelor's thesis 32 pages
May 2023
JavaScript is the most popular language used to build websites and web
applications. It has some limitations such Lack of static typing and limited support
for object-oriented programming. TypeScript, a language developed by Microsoft,
addresses these issues by providing a statically typed, object-oriented alternative
to JavaScript. In this thesis, evaluates how effective TypeScript is for his web
development by comparing features such as static typing, interfaces, and
modules with those of JavaScript. We also explore how TypeScript impacts
productivity, code organization, maintainability, and reliability of large-scale web
applications. Conduct a case study of a real web development project to compare
results using TypeScript and JavaScript.
3
CONTENTS
1 INTRODUCTION ..................................................................................... 5
2 THEORETICAL BACKGROUND ............................................................ 6
2.1 History and Evolution of Typescript ................................................. 6
2.2 Key Features, Including Static Typing, Interfaces, and Modules .... 7
2.2.1 Static Typing ........................................................................... 7
2.2.2 Interfaces ................................................................................ 8
2.2.3 Modules................................................................................... 9
2.3 Comparison With JavaScript .......................................................... 10
2.3.1 Processing Time Difference ................................................. 13
3 USE CASES OF TYPESCRIPT ............................................................ 15
3.1 TypeScript in Action........................................................................ 15
3.2 Advantages and disadvantages of using TypeScript .................... 16
3.3 Compatibility with Popular Frameworks (Angular and React)....... 16
3.3.1 Angular with TypeScript ....................................................... 17
3.3.2 React with TypeScript........................................................... 17
3.4 Case Studies of Companies & Organizations Using TypeScript .. 18
3.4.1 Microsoft ............................................................................... 19
3.4.2 Slack ..................................................................................... 19
3.4.3 Airbnb .................................................................................... 19
3.4.4 Asana .................................................................................... 19
4 IMPACT OF TYPESCRIPT ON WEB DEVELOPMENT ...................... 20
4.1 Improved code maintainability and scalability ............................... 20
4.2 Early error detection and debugging .............................................. 20
4.3 Improved Productivity (Visual Code) ............................................. 21
4.4 Limitations and Challenges of TypeScript ..................................... 22
4.5 Compatibility Issues with Some Libraries and Frameworks.......... 22
4.6 Performance Considerations.......................................................... 23
4.7 TypeScript Community and Ecosystem ......................................... 24
4.8 The Importance of TypeScript Popularity ...................................... 25
4.8.1 Stack Overflow ...................................................................... 25
4.8.2 GitHub ................................................................................... 27
4.8.3 Google Trends ...................................................................... 28
4.9 Potential Drawbacks ....................................................................... 29
5 DISCUSSION ........................................................................................ 30
REFERENCES ........................................................................................... 31
4
JS JavaScript
TS TypeScript
5
1 INTRODUCTION
JavaScript and TypeScript are two of the most widely used programming
languages for web development. While JavaScript has been a essential language
for web development since its inception, TypeScript has been gaining popularity
in recent years as a "superset" of JavaScript that adds optional static typing and
other features.
In this paper, we will explore the features and benefits of TypeScript in web
development, examine its impact on the development landscape, and evaluate
its effectiveness as an alternative to JavaScript in various use cases. We will also
look at the current state of the industry and see how the two languages are being
used in real-world projects. Additionally, we will discuss the challenges and
limitations of using TypeScript and provide recommendations for developers and
organizations considering adopting it as their primary language for web
development.
2 THEORETICAL BACKGROUND
Over time, Typescript has evolved and improved, adding new features and
improvements with each new version. In 2015 Typescript 1.5 was released
adding support for decorators and his ES6 generator. Typescript 1.6, released in
2015, added support for React and JSX. In 2016, Typescript 2.0 was released,
introducing features like optional concatenation, null coalescing, and readonly
properties. Typescript 2.1, released later this year, added support for async/await
functions and rest/spread properties on objects. Typescript 2.3 was released in
2017 and added support for generic parameter default values and conditional
types. Typescript 2.4, released later that year, added support for dynamic import
7
TypeScript begins with JavaScript and ends with JavaScript. Typescript adopts
the basic building blocks of our program from JavaScript. That being so, only
need to know JavaScript to use TypeScript. All TypeScript code is converted into
its JavaScript analogous for the purpose of execution (Tutorialspoint 2023). It
provides a powerful and flexible alternative to JavaScript, offering developers a
more structured and efficient approach to web development.
Static typing is a key feature of TypeScript that allows developers to declare the
data types of variables, function parameters, and return types at compile-time.
This helps catch errors early in the development process and makes your code
more reliable (Tutorialspoint 2023).
When calling the calculateArea function, the expected argument types are also
specified as number. This is because the function expects two numeric arguments
and returns a numeric value. The result of the function call is assigned to a
variable area which is also declared as a number.
2.2.2 Interfaces
In figure 2, defined an interface Product that requires all product objects to have
id, name, price, inStock, and getDiscountedPrice properties. The
description property is optional, indicated by the question mark “?”. Then create
9
a product object that implements the Product interface. It has all the required
properties and the getDiscountedPrice method that takes a discount percentage
and returns the discounted price.
2.2.3 Modules
TypeScript also has a modular architecture, allowing developers to use only the
features they need, and its syntax is similar to that of JavaScript, making it easy
for developers to learn and use. It supports all the features of JavaScript,
including the latest ECMAScript standards, and can be used in any environment
that supports JavaScript, including web browsers, servers, and mobile devices
(Tutorialspoint 2023).
Let's say we have a file called [Link] that exports a function for adding two
numbers:
Then, in another file called [Link], we can import that function and use it:
10
Using modules in this way can help keep our code organized and make it easier
to reuse functionality across multiple files.
While the differences in this simple example may not seem significant,
TypeScript's features become more valuable in larger and more complex
applications, where type safety, better error detection, and improved code editor
support can significantly enhance the development process.
Type Annotations: In the TypeScript example, we specify the types for variables
and function parameters, which helps catch type-related errors during
development and improves code quality.
A quiz app built using TypeScript involves creating multiple components that work
together to provide a seamless user experience. When building a quiz app with
TypeScript, we start by setting up the project structure and organizing our code.
We define data structures like questions, answers, and user profiles using
TypeScript's interfaces and types to catch errors early. Then, we create reusable
components using classes and inheritance for different types of quiz questions.
We also use popular front-end frameworks like Angular or React to build the user
interface and integrate the app with a back-end server using TypeScript and
[Link]. This way, we can handle user authentication and manage quiz data.
TypeScript also helps us create custom UI components and reusable libraries if
needed.
TypeScript is highly compatible with popular web frameworks like Angular and
React, as both frameworks have built-in support for TypeScript. This compatibility
enables developers to take advantage of TypeScript's features when building
applications with Angular or React, leading to improved code quality and
maintainability.
17
Angular has built-in TypeScript support, and the Angular framework itself is
written in TypeScript. The Angular CLI, which is used to generate, develop, and
manage Angular projects, uses TypeScript by default. TypeScript's static typing
and interfaces integrate seamlessly with Angular's component-based
architecture, dependency injection, and decorators, resulting in a more robust
and maintainable codebase.
FIGURE 8. Angular With TypeScript Code Example (Open AI, ChatGpt 2023)
React also supports TypeScript and can easily set up a TypeScript-based React
project using Create React App with the TypeScript template. TypeScript works
well with React's functional components, hooks, and the overall component
architecture. It allows developers to create strongly typed props and state, leading
to better error checking during development and making it easier to refactor and
maintain the codebase.
18
FIGURE 9. React With TypeScript Code Example (Open AI, ChatGpt 2023)
3.4.1 Microsoft
3.4.2 Slack
3.4.3 Airbnb
3.4.4 Asana
TypeScript has had a significant impact on web development since its release in
2012. It has improved code quality by providing developers with a powerful tool
to detect errors before they runtime. Its advanced features have also improved
productivity and made it easier to write and maintain complex applications. It’s
static typing and code structure have enabled better collaboration among
developers and increased adoption of JavaScript frameworks.
TypeScript also offers features like code completion and refactoring support,
which can help developers quickly navigate code and make changes efficiently.
These features can make it easier to refactor code, add new features, or modify
existing functionality without introducing errors or breaking the code. The
improved maintainability and scalability provided by TypeScript can help
developers build more reliable and maintainable web applications. By writing
cleaner, more organized, and more reliable code, developers can reduce
development time and ensure that their code can be maintained and scaled
effectively over time (Dojo 2023).
language like JavaScript, this error would only be caught at runtime, leading to
unexpected behavior and potentially difficult-to-debug issues. However, with
TypeScript, this error would be caught at compile-time, allowing to fix the issue
before it becomes a problem.
FIGURE 10. Early Error Detection and Debugging (Open AI, ChatGpt 2023).
In addition to catching errors early, TypeScript can also improve the debugging
experience by providing more informative error messages. The strong typing of
TypeScript allows for more detailed error messages, making it easier for
developers to identify and fix issues in their code.
TypeScript has its limitations and challenges that need to be considered when
using it in web development. One of the challenges is that it has a steeper
learning curve compared to JavaScript, especially for developers who are not
familiar with static typing or advanced features like classes and interfaces.
Additionally, not all existing JavaScript libraries and tools have TypeScript
support, which can make it difficult to integrate TypeScript into existing projects
or use certain libraries and tools (Marius 2021).
Another challenge is that since TypeScript needs to be compiled to JavaScript,
there is an additional step in the development process that can slow down
iteration cycles and increase build times. While TypeScript's static typing provides
many benefits, it can also be limiting in some cases. For example, some dynamic
or loosely-typed scenarios may require more flexibility than TypeScript allows.
Therefore, it is essential to weigh the benefits against the costs and assess
whether TypeScript is the best choice for a particular project. While TypeScript
can improve code quality, productivity, and maintainability, developers should
consider its limitations and challenges before using it (Gustav n.d).
One of the challenges that developers may face when using TypeScript in web
development is compatibility issues with some libraries and frameworks. This is
because not all existing JavaScript libraries and frameworks have TypeScript
support, which can make it difficult to integrate TypeScript into existing projects
or use certain libraries and tools.
But still there is good news: many popular JavaScript libraries and frameworks
have added TypeScript support in recent years, making it easier for developers
to use TypeScript in their projects. Despite this progress, it's still possible that
23
developers will need to write custom type definitions for libraries that do not have
TypeScript support, which can be time-consuming and not always provide a
complete solution.
To help bridge the gap, TypeScript provides tools like declaration files and the
any type that can help developers work with existing JavaScript code that does
not have TypeScript support. While compatibility issues with some libraries and
frameworks can be a challenge, the increasing popularity and adoption of
TypeScript are driving more libraries and frameworks to support it (TypeScript
Handbook 2023)
Moreover, while there may be some challenges when using TypeScript in web
development, the benefits it provides in terms of improved code quality,
productivity, and maintainability make it worth considering. By keeping an eye on
compatibility issues and using the tools available, developers can take advantage
of the language's strengths and continue to use it effectively in their projects.
Finally, code size can be impacted by TypeScript due to the additional typing
information and language features. This can impact page load times and overall
performance. To minimize code size, developers can use techniques like tree
shaking and minification to remove unused code and compress the codebase.
Overall, while TypeScript can introduce some performance overhead, these
issues can be minimized by using best practices and optimization techniques. By
using TypeScript effectively, developers can improve code quality and
maintainability while ensuring that their applications are performant and efficient
(JSdairies 2019).
has also led to more libraries and frameworks adding TypeScript support, making
it easier for developers to integrate TypeScript into their projects
FIGURE 11. Stack Overflow Survey list 2021 (Stack Overflow Developer Survey
n.d)
TypeScript has been steadily growing in popularity among developers over the
past few years. According to the Stack Overflow Developer Survey 2021, It was
the 5th most commonly used technology among professional developers
worldwide, with 36.2%. This places TypeScript ahead of other popular web
development technologies such as [Link], Angular, and Ruby on Rails.
Furthermore, TypeScript was also among the top 5 most loved programming
languages, with 73.1% of respondents saying they loved working with it. This
highlights the popularity of TypeScript among developers and its growing
adoption in the web development community
27
4.8.2 GitHub
According to the 2021 GitHub State of the Octoverse report, TypeScript was the
4th most popular language on GitHub, based on the number of repositories
created in 2021, with over 2.3 million repositories. Certainly! The Hashicorp
Configuration Language (HCL) has become more popular over the past year,
largely due to the growing popularity of the Terraform tool and Infrastructure as
Code (IaC) practices that automate deployments. As a result, other languages
like Go. TypeScript have also seen significant increases in usage.
JavaScript remains the most widely used programming language, and Python
has maintained its second place position due to its versatility across various
domains such as development, education, machine learning, and data science.
TypeScript, a superset of JavaScript that adds features like static typing, has also
maintained its position as the fourth most popular language year-over-year.
Interestingly, PHP dropped from sixth to seventh place in the 2022 rankings.
According to Google Trends, the popularity of TypeScript has been on the rise
over the past 5 years. There has been a steady increase in interest in TypeScript,
with a significant spike in early 2021. This suggests that TypeScript is becoming
more widely used and adopted by developers around the world.
5 DISCUSSION
As web development evolves, developers are constantly looking for better ways
to write efficient and maintainable code. That's where TypeScript comes in - it's
a superset of JavaScript that offers several benefits over its prior. TypeScript
provides early error detection, better tooling support, and cleaner syntax, which
helps developers improve the quality of their code and increase productivity.
However, it's worth observing that switching to TypeScript from JavaScript may
come with some challenges. Developers who are already comfortable with
JavaScript may need to put in some effort to learn TypeScript. Additionally,
transpiling TypeScript to JavaScript adds an extra step to the development
process, which could slow things down. Despite these challenges, TypeScript's
benefits make it a worthwhile investment for developers, especially for larger-
scale projects where writing efficient and maintainable code is critical. It's no
surprise that major companies like Microsoft and Google are adopting TypeScript
in their development workflows, further upgrowth its effectiveness in web
development.
REFERENCES
Mad Devs. n.d. Quick start with Typescript and React. Read 05.02.2023
[Link]
components-typescript/
Alexsoft. 2020. The Good and the Bad of TypeScript Read 16.04.2023
[Link]
33