TypeScript Tutorial | A Step-By-Step Guide to Learn
Introduction to TypeScript Tutorial ACTE

TypeScript Tutorial | A Step-By-Step Guide to Learn

Last updated on 02nd Feb 2022, Blog, Tutorials

About author

Manish Pandey (IT DevOps Cloud Senior Engineer )

Manish Pandey is a IT DevOps Cloud Senior Engineer. He has expertise in Trending Domains like Data Science, Artificial Intelligence, Machine Learning, Blockchain, etc. His articles help the learners to get insights about the Domain.

(5.0) | 18597 Ratings 1846
    • Introduction to TypeScript
    • What is TypeScript?
    • Features of TypeScript
    • TypeScript and ECMAScript
    • Why Use TypeScript?
    • The advantages of TypeScript incorporate
    • Components of TypeScript
    • Declaration Files
    • TypeScript – Modules
    • TypeScript – Interfaces
    • Benefits of TypeScript
    • TypeScript – Functions
    • TypeScript – Arrow Functions
    • History
    • TypeScript Build Tools
    • Conclusion

    Subscribe For Free Demo


      Introduction to TypeScript

      TypeScript allows you to compose JavaScript in the manner in which you need to. TypeScript is a composed superset of JavaScript that gathers to plain JavaScript. TypeScript is an unadulterated item arranged with classes, interfaces, and statically composed like C# or Java. The famous JavaScript system Angular 2.0 is written in TypeScript. Dominating TypeScript can assist developers with composing object-situated projects and have them arranged to JavaScript, both on the server-side and client-side.

      TypeScript is an Open Source Object Oriented programming language created and kept up with by Microsoft Corporation. TypeScript is a specific language and its first form was presented in 2012. It is a Strict Super Set of JavaScript, and that amounts to something that is executed in JavaScript can be carried out utilizing TypeScript alongside the decision of adding upgraded highlights (each current JavaScript Code is a legitimate TypeScript Code). As TypeScript code is changed over to JavaScript code it makes it simpler to coordinate into JavaScript projects. It is planned mostly for enormous scope projects.


      Developers coming from the Object-Oriented world will find it simple to utilize TypeScript. With the information on TypeScript, they can construct web applications a lot quicker, as TypeScript has great tooling support.


      As a peruser of this instructional exercise, you ought to have a decent comprehension of OOP ideas and fundamental JavaScript, to take advantage of this instructional exercise.


    • The typeScript was first unveiled in October 2012 (at rendition 0.8), following two years of inner improvement at Microsoft. Not long after the declaration, Miguel de Icaza lauded the actual language yet scrutinized the absence of mature IDE support separated from Microsoft Visual Studio, which was not accessible on Linux and OS X around then. As of April 2021, there is support in other IDEs and content tools, including Emacs, Vim, Webstorm, Atom[18], and Microsoft’s own Visual Studio Code.

    • TypeScript 0.9, delivered in 2013, added help for generics. TypeScript 1.0 was delivered at Microsoft’s Build designer meeting in 2014. Visual Studio 2013 Update 2 offers worked in help for TypeScript.

    • In July 2014, the advancement group reported another TypeScript compiler, asserting 5× execution gains. At the same time, the source code, which was at first facilitated on CodePlex, was moved to GitHub.

    • On 22 September 2016, TypeScript 2.0 was delivered; it presented a few elements, including the capacity for developers to alternatively keep factors from being relegated invalid qualities, some of the time alluded to as the billion-dollar botch.

    • TypeScript 3.0 was delivered on 30 July 2018, bringing numerous language augmentations like tuples in rest boundaries and spread articulations, rest boundaries with tuple types, nonexclusive rest boundaries, etc.

    • TypeScript 4.0 was delivered on 20 August 2020. While 4.0 didn’t present any breaking transforms, it added language elements like Custom JSX Factories and Variadic Tuple Types.

    • What is TypeScript?

      By definition, “TypeScript is JavaScript for application-scale advancement.” TypeScript is a specific, object-arranged, accumulated language. It was planned by Anders Hejlsberg (originator of C#) at Microsoft. TypeScript is both a language and a bunch of instruments. TypeScript is a composed superset of JavaScript aggregated to JavaScript. All in all, TypeScript is JavaScript in addition to a few extra highlights.

      Features of TypeScript

      TypeScript is simply JavaScript. TypeScript begins with JavaScript and finishes with JavaScript. Typescript embraces the essential structure squares of your program from JavaScript. Subsequently, you just need to know JavaScript to utilize TypeScript. All TypeScript code is changed over into its JavaScript comparable for execution.

      TypeScript upholds other JS libraries. Ordered TypeScript can be consumed from any JavaScript code. TypeScript-produced JavaScript can reuse all of the current JavaScript systems, instruments, and libraries.

      JavaScript is TypeScript. This implies that any legitimate .js record can be renamed to .ts and accumulated with other TypeScript documents.

      TypeScript is versatile. TypeScript is versatile across programs, gadgets, and working frameworks. It can run on any climate that JavaScript runs on. Dissimilar to its partners, TypeScript needn’t bother with a devoted VM or a particular runtime climate to execute.

      TypeScript and ECMAScript

      The ECMAScript particular is a normalized detail of a prearranging language. There are six versions of ECMA-262 distributed. Adaptation 6 of the standard is codenamed “Congruity”. TypeScript is lined up with the ECMAScript6 particular.

      TypeScript embraces its essential language highlights from the ECMAScript5 detail, i.e., the authority determination for JavaScript. TypeScript language highlights like Modules and class-based direction are following the EcmaScript 6 particular. Furthermore, TypeScript additionally accepts highlights like generics and type explanations that aren’t a piece of the EcmaScript6 detail.

      Why Use TypeScript?

      TypeScript is better than its different partners like CoffeeScript and Dart programming dialects such that TypeScript is broadened JavaScript. Interestingly, dialects like Dart, CoffeeScript are new dialects in themselves and require a language-explicit execution climate.

      The advantages of TypeScript incorporate

      Aggregation − JavaScript is a deciphered language. Subsequently, it should be raced to test whether it is legitimate. It implies you compose every one of the codes just to observe no result if there is a mistake. Henceforth, you need to go through hours attempting to track down bugs in the code. The TypeScript transpiler gives the blunder taking a look at include. TypeScript will arrange the code and create aggregation blunders assuming it discovers sentence structure mistakes of some kind or another. This assists with featuring blunders before the content is run.

      Solid Static Typing − JavaScript isn’t specifically. TypeScript accompanies a discretionary static composting and types surmising framework through the TLS (TypeScript Language Service). The kind of variable announced with no sort might be construed by the TLS because of its worth. TypeScript upholds type definitions for existing JavaScript libraries. TypeScript Definition record (with .d.ts augmentation) defines outside JavaScript libraries. Subsequently, TypeScript code can contain these libraries.

      Course Curriculum

      Develop Your Skills with JavaScript Certification Training

      Weekday / Weekend BatchesSee Batch Details

      Components of TypeScript

      At its heart, TypeScript has the accompanying three parts −

      Language − It involves sentence structure, watchwords, and type explanations.

      The TypeScript Compiler − The TypeScript compiler (tsc) changes over the directions written in TypeScript to its JavaScript same.

      The TypeScript Language Service − The “Language Service” uncovered an extra layer around the center compiler pipeline that is an editorial manager-like application. The language administration upholds the normal arrangement of common proofreader tasks like explanation consummation, signature help, code designing and laying out, colorization.

      Declaration Files

      Whenever a TypeScript script gets aggregated, there is a choice to create an announcement record (with the expansion .d.ts) that capacities as a connection point to the parts in the accumulated JavaScript. The idea of revelation records is undifferentiated from the idea of header documents viewed as in C/C++. The affirmation records (documents with .d.ts expansion) give IntelliSense to types, work calls, and variable help for JavaScript libraries like jQuery, MooTools, and so forth.

      TypeScript – Modules

      Inward Module

      Inward modules came in the previous form of Typescript. This was utilized to sensibly bunch classes, interfaces capacities into one unit and can be traded in another module. This consistent gathering is named namespace in the most recent variant of TypeScript. So inward modules are old rather we can utilize namespace. Inward modules are as yet upheld, however, it’s prescribed to utilize namespace over interior modules.

      Outer Module

      Outer modules in TypeScript exist to determine and stack conditions between different outside js documents. On the off chance that there is just a single js record utilized, outer modules are not applicable. Generally, reliance on the board between JavaScript records was finished utilizing program script labels (<'script>). However, that is not extendable, as it’s exceptionally straight while stacking modules. That implies as opposed to stacking documents in a steady progression there is no nonconcurrent choice to stack modules. Whenever you are customizing js for the server for instance NodeJs you don’t have script labels.

      There are two situations for stacking wards’ js documents from a solitary principle JavaScript record.

    • Client-Side – RequireJs
    • Server Side – NodeJs

    • Choosing a Module Loader

      To help stack outside JavaScript records, we want a module loader. This will be another js library. For programs the most well-known library utilized is RequieJS. This is an execution of the AMD (Asynchronous Module Definition) particular. Rather than stacking documents in a steady progression, AMD can stack them all independently, in any event, when they are subject to one another.

      Characterizing External Module

    • While characterizing an outside module in TypeScript focusing on CommonJS or AMD, each document is considered as a module. So it’s discretionary to utilize the inner module inside the outside module.

    • If you are moving TypeScript from AMD to CommonJs module frameworks, there is no extra work required. The main thing you want to change is only the compiler banner Unlike in JavaScript there is an upward in moving from CommonJs to AMD or the other way around. The language structure for pronouncing an outside module is utilizing the catchphrases ‘commodity’ and ‘import’.

    • TypeScript – Interfaces

      The point of interaction is a design that characterizes the agreement in your application. It characterizes the sentence structure for classes to follow. Classes that are gotten from a point of interaction should follow the construction given by their point of interaction. The TypeScript compiler doesn’t change the point of interaction over to JavaScript. It involves a connection point for type checking. This is otherwise called “duck composing” or “underlying subtyping”. A connection point is characterized by the watchword connection point and it can incorporate properties and strategy announcements utilizing a capacity or a bolt work.

      In the above model, the representative point of interaction incorporates two properties utilized and empName. It additionally incorporates a technique affirmation getSalaray utilizing a bolt work that incorporates one number boundary and a number bring type back. The getManagerName strategy is announced utilizing an ordinary capacity. This implies that any object of type worker should characterize the two properties and two strategies.

      Interface as Type

    • Interface in TypeScript can be utilized to characterize a sort and to carry out it in the class.
    • The accompanying connection point IEmployee characterizes a kind of factor.
    • In the above model, a connection point KeyPair incorporates two properties key and worth. A variable kv1 is pronounced as KeyPair type. Along these lines, it should follow a similar design as KeyPair. It implies just an article with properties key of number sort and benefit of string type can be appointed to a variable kv1.
    • The TypeScript compiler will show a mistake assuming there is any adjustment of the name of the properties or the information type is not the same as KeyPair.
    • One more factor kv2 is additionally pronounced as KeyPair type however the allocated esteem is esteem rather than esteem, so this will cause a blunder.
    • Similarly, kv3 allocates a number to the worth property, so the compiler will show a blunder. Hence, TypeScript utilizes a point of interaction to guarantee the appropriate construction of an item.

    • Interface as Function Type

      A typeScript connection point is additionally used to characterize a sort of capacity. This guarantees the capacity signature. In the above model, a connection point KeyValueProcessor incorporates a strategy signature. This characterizes the capacity type. Presently, we can characterize a variable of type KeyValueProcessor which can highlight capacities with a similar signature as characterized in the KeyValueProcessor interface. Along these lines, add key-worth or update key-esteem work is appointed to keep. In this way, kvp can be known as a capacity.

      Interface for Array Type

      A connection point can likewise characterize the sort of an exhibit where you can characterize the kind of file as well as qualities. In the above model, interface NumList characterizes a kind of exhibit with a list as a number and worth as a number sort. Similarly, IStringList characterizes a string cluster with a list as a string and worth as a string.

      Discretionary Property

      Now and then, we might proclaim a point of interaction with abundance properties yet may not anticipate that all articles should characterize all the given connection point properties. We can have discretionary properties, set apart with a “?”. In such cases, objects of the connection point might characterize these properties. In the above model, temp dept is set apart with ?, so objects of IEmployee might incorporate this property.

      Peruse just Properties

      TypeScript gives a method for denoting a property as perused as it were. This implies that once a property is allocated a worth, it can’t be changed! In the above model, the SSN property is perused as it were. We characterize the personObj object of type Citizen and dole out qualities to the two connection point properties. Then, we attempt to change the qualities appointed to both the properties-name and SSN. The TypeScript compiler will show a mistake when we attempt to change the read-just SSN property.

      Expanding Interfaces

      Connection points can broaden at least one point of interaction. This makes composing connection points adaptable and reusable. In the above model, the representative connection point expands the individual point of interaction. In this way, objects of IEmployee should incorporate every one of the properties and strategies for the individual point of interaction if not, the compiler will show a mistake.

      Executing an Interface

    • Like dialects like Java and C#, interfaces in TypeScript can be executed with a Class. The Class carrying out the connection point needs to rigorously adjust to the construction of the connection point.

    • In the above model, the representative point of interaction is executed in the Employee class utilizing the carry-out watchword. The carrying out class ought to rigorously characterize the properties and the capacity with a similar name and information type. If the executing class doesn’t follow the design, then, at that point, the compiler will show a mistake.

    • The executing class can characterize additional properties and strategies, yet basically, it should characterize every one of the individuals from a point of interaction.

    • Benefits of TypeScript

      Since in the end Typescript produces Javascript, you might ask why not use javascript straightforwardly. The Benefit of TypeScript accompanies its sort framework, which gives a few advantages over javascript.

      Discretionary Type System

      TypeScript gives the static sort framework which gives incredible assistance in discovering programming mistakes at the aggregate time. Javascript is a progressively composed framework. The factors can hold any qualities. The kind of not entirely set in stone on the fly. The javascript verifiably changes types for instance strings over to a number. This is alright for a little application, but for huge applications, this can be a ton of cerebral pains. It is hard to test to check whether the legitimate sorts are passed and mistakes generally occur at runtime.

      Intellisense and linguistic structure checking

      The static Type framework gives better tooling support in IDE. The IntelliSense, punctuation checking, and code fruition are a couple of the significant advantages you get with the tooling support. This rates up the advancement time and guarantees that the software engineers commit fewer errors with mistakes. Every one of the significant editors like VSCode, particle, wonderful text incorporates the tooling support for Typescript

      Viable code

      Typescript brings Types, Classes, interfaces, and modules. it makes the code more viable and adaptable. It is a lot more straightforward to put together the Typescript code than a Javascript code

      Language Enhancement

      Typescript accompanies a few language highlights. It upholds Encapsulation through classes and modules. Uphold’s constructors, properties, and capacities. It has support for Interfaces. You can utilize Arrow capacities or lambdas or unknown capacities.

      You are as yet utilizing Javascript

      The Typescript is still Javascript. It holds a large portion of the javascript language structure. This implies that all substantial JavaScript code is legitimate TypeScript code. Henceforth the expectation to absorb information is lean. If you don’t know about OOP ideas like classes, interfaces, and so forth, you might have to learn them to get the best out of Typescript

      Typescript Components

      The design of TypeScript is flawlessly coordinated in various layers as displayed in the picture underneath. The three significant layers are Center TypeScript Compiler.

    • Typescript Standalone Compiler
    • Typescript Language Services

    • Center TypeScript Compiler

      The TypeScript compiler deals with the errand of type-really looking at our code and changing over it to substantial JavaScript code. Deeply, program, scanner, parser, checker and producer, and so forth

      Independent compiler (tsc)

      The cluster arrangement CLI. Mostly handle perusing and composing records for various upheld motors (for example Node.js)

      Language Service

      The Language Service upholds the editors and different devices to give better help with carrying out elements like IntelliSense, code finish, organizing and illustrating, colorization, code re-calculating like rename, Debugging connection point assistants like approving breakpoints, and so on.

      TypeScript – Functions

      Capacities are the essential squares of any program. In JavaScript, capacities are the main part since JavaScript is a practical programming language. With capacities, you can carry out/copy the ideas of items arranged to program like classes, articles, polymorphism, and, deliberation.

      Capacities guarantee that the program is viable and reusable, and coordinated into clear squares. While TypeScript gives the idea of classes and modules, works are an indispensable piece of the language. In TypeScript, capacities can be of two sorts: named and unknown.

      Course Curriculum

      Get JOB Oriented JavaScript Training for Beginners By MNC Experts

      • Instructor-led Sessions
      • Real-life Case Studies
      • Assignments
      Explore Curriculum

      Named Functions

      A named work is one where you proclaim and call a capacity by its given name. Capacities can likewise incorporate boundary types and bring types back.

      Mysterious Function

      A mysterious capacity is characterized as an articulation. This articulation is put away in a variable. Thus, the actual capacity doesn’t have a name. These capacities are conjured utilizing the variable name that the capacity is put away in. A mysterious capacity can likewise incorporate boundary types and bring types back.

      Work Parameters

      Boundaries are qualities or contentions passed to a capacity. In TypeScript, the compiler anticipates that a capacity should get the specific number and sort of contentions as characterized in the capacity signature. Assuming the capacity expects three boundaries, the compiler makes sure that the client has passed qualities for every one of the three boundaries for example it checks for accurate matches. This is not normal for JavaScript, where it is adequate to pass fewer contentions than what the capacity anticipates. The boundaries that don’t get a worth from the client are thought of as vague.

      Discretionary Parameters

      TypeScript has discretionary boundary usefulness. The boundaries that might get a worth can be added with a ‘?’ to check them as discretionary. In the above model, the subsequent boundary name is set apart as discretionary with a question mark added toward the end. Henceforth, the capacity Greet() acknowledges either 1 or 2 boundaries and returns a hello string. On the off chance that we don’t indicate the subsequent boundary then, at that point, its worth will be unclear.

      Default Parameters

      TypeScript gives the choice to add default esteems to boundaries. In this way, if the client doesn’t offer a benefit to a contention, TypeScript will instate the boundary with the default esteem. Default boundaries have similar conduct as discretionary boundaries. On the off chance that worth isn’t passed for the default boundary in a capacity call, the default boundary should follow the expected boundaries in the capacity signature. Henceforth, default boundaries can be precluded while calling a capacity. Nonetheless, assuming that a capacity signature has a default boundary before an expected boundary, the capacity can in any case be called, given the default boundary is passed a worth of indistinct.

      TypeScript – Arrow Functions

    • Fat bolt documentations are utilized for mysterious capacities i.e for work articulations. They are additionally called lambda capacities in different dialects.

    • Utilizing fat bolt =>, we dropped the need to utilize the capacity catchphrase. Boundaries are passed in the enclosure (), and the capacity articulation is encased inside the wavy sections { }.

    • The fat bolt => isolates the capacity boundaries and the capacity body. The right half of => can contain at least one code articulation. The above bolt work aggregate will be changed over into the accompanying JavaScript code.

    • TypeScript Build Tools

      Assemble apparatuses are customizing utilities that assist to robotize the change and packaging of our source code into a solitary record. A form instrument utility is utilized to fabricate another variant of a program. Building implies incorporating, connecting, and bundling the code into the executable structure. The Build apparatuses are generally run on the order line, either in IDE or different from it.

      Whenever you use JavaScript or TypeScript to program a section or all of your application rationale, you can incline toward ReSharper. Its elements are accessible in .js, .ts, .d.ts, and .json records, in JavaScript code inserted in HTML documents, as well as in JSX language structure. Fabricating instruments or constructing computerization is the demonstration of prearranging or robotizing an assortment of assignments that engineers do in their everyday exercises. These are:

    • Downloading conditions.
    • Assembling source code into twofold code.
    • Bundling that twofold code.
    • Running tests.
    • Sending to creation frameworks.

    • Utilization of fabricated instruments

      In little activities, the product designers physically conjure the form cycle, which is anything but a decent practice for bigger tasks. It is because, in bigger tasks, it is exceptionally difficult to monitor what should be worked, in what arrangement, and what should be the conditions in the structure interaction. So we utilize a mechanization device that permits the form interaction to be more reliable.

      Code investigation

      ReSharper’s code investigation highlights assist you with rapidly finding and right mistakes and issues with around 100 code reviews for JavaScript and TypeScript code, and around 50 TypeScript-explicit assessments. Essentially every one of the recognized issues can be in a flash fixed with handy solutions.

      In the model here, composing = where == was expected, could prompt an exceptionally unpretentious bug… in any case, not with ReSharper. While examining your code, ReSharper considers the language level, which is configurable. Of course, a language level is chosen because of undertaking settings, yet you can supersede the setting if important.

      Route and search

    • The vast majority of ReSharper’s route and search highlights are accessible in JavaScript and TypeScript. To no one’s surprise, all orders for a route from explicit images are accessible with the Navigate To alternate way: Alt+’.

    • All your beloved inquiry orders, like Ctrl+T (Go to Everything/Type) and Ctrl+Shift+T (Go to File), are accessible also. All upheld route and search highlights consider the points of interest of JavaScript and TypeScript sentence structure. For instance, File Structure can show information sorts of boundaries on the off chance that they are determined in XML documentation.

    • Primary Search and Replace is likewise mindful of JavaScript/TypeScript grammar.

    • Code fulfillment

      Code fulfillment highlights assist you with composing JavaScript/TypeScript code quicker. While you type, ReSharper examines the encompassing setting and images you as of late entered to propose reasonable qualities in the finishing list. For instance, ReSharper can assist you with finding works in JavaScript techniques and properties, as well as images from JavaScript libraries referred to in the current undertaking.

      Setting activities and different aides

      ReSharper allows you rapidly to change over pieces of your JavaScript/TypeScript code with 50 setting activities for JavaScript and TypeScript in addition to around 20 TypeScript-explicit activities. The entire munitions stockpile of other ReSharper coding help treats – punctuation featuring, rework code, expand/contract determination, just to give some examples – is likewise available to you in JavaScript and TypeScript code.

      JSDoc support

      ReSharper makes JSDoc remarks a lot simpler to peruse by featuring their language structure. At the point when you type JSDoc remarks, ReSharper helps you by finishing your feedback. For instance, you can type/** over a capacity and ReSharper will produce documentation hits for all boundaries and bring esteem back. JSDoc types, typedefs, and callbacks are additionally appropriately featured and opened up in code fulfillment. Moreover, all JSDoc remarks for images are accessible on the uses of these images in the Quick Documentation spring up.

      Ordinary articulation help

      ReSharper’s help for ordinary articulations incorporates a full comprehension of JavaScript/TypeScript customary articulations. As a matter of course, customary articulations are perceived in standard articulation literals, RegExp constructors, and techniques, as well as in String object strategies: match(), search(), supplant(), split(). Notwithstanding, you can continuously advise ReSharper to examine any string exacting as a normal articulation.


      In JavaScript and TypeScript code, you can partake in a few refactorings that work equivalent to in C#: Inline Variable, Introduce Variable, Introduce Variable for Substring, and Rename. In TypeScript, a bunch of refactorings on types is accessible: Copy Type, Introduce Field, Move Type to Another File or Namespace, and Move to Folder. There is additionally one refactoring explicit to JavaScript/TypeScript: Move to Resource. This refactoring works in JavaScript/TypeScript projects made from Visual Studio layouts (for example Apache Cordova) and permits moving string literals to asset documents. All JavaScript/TypeScript refactorings are additionally accessible in JSX linguistic structure.

      Make from Usage

      ReSharper permits you to utilize non-existing images and afterward produce legitimate executions because of these utilizations in practically completely upheld dialects. JavaScript and TypeScript are no special cases – for any unsettled image ReSharper will propose at least one method for making it.

      Produce Constructors

      At the point when you press Alt+Insert on a TypeScript type assertion, ReSharper allows you rapidly to make a constructor for this sort. The constructor age wizard makes a non-default constructor that takes chosen fields from the sort and base sorts as boundaries.

      Angular JS Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download


    • TypeScript carries a ton of advantages to our efficiency and designer experience. We’ve seen that incorporating it with a current JavaScript project is simple and conveys practically no upward. TypeScript isn’t special to Angular, other strong frontend systems, for example, React and Vue is beginning to be utilized with TypeScript to permit designer groups to make applications that are dependable, manageable, and adaptable. JavaScript and TypeScript are consistently advancing yet not going up against one another.

    • The typeScript was made to supplement and improve JavaScript – not supplant it. The future might see them turning out to be the same in highlights yet with TypeScript staying the statically-composed other option. Assuming you’re keen on taking your TypeScript abilities to an extreme level, I welcome you to come and learn TypeScript fundamental and progressed ideas with me at Ultimate Courses – just relax on the off chance that you are not an Angular engineer, the course is planned totally around TypeScript!

    Are you looking training with Right Jobs?

    Contact Us
    Get Training Quote for Free