Typescript is a strongly typed superset of JavaScript that compiles to plain JavaScript now you can use this language for application scaled JavaScript development also it can be executed on any browser any host and any operating system hi everyone this is Shannon Ephraim at irika and in today’s session we will talk about what is typescript and why do we need to use it now before we begin let’s have a look after this agenda so first we will discuss what is typescript and then we will see why do we actually need to use typescript then we will talk about some of the features of typescript and also the benefits then moving on we will have a look at the different components and then the different steps involved in installing typescript then we will talk about the working of typescript with an example and finally we will discuss the difference between typescript and JavaScript now if you are looking for an online training certification in web development now talking about what is typescript so typescript is a typed superset of JavaScript that compiles to plain JavaScript it is pure object oriented with classes interfaces and statically typed programming languages like C sharp or Java you will need a compiler to compile and generate the code in the JavaScript file basically typescript is the es6 version of javascript with some additional features now our typescript code is written in a file with the dot TS extension and then compiled into JavaScript using the compiler.

you can write the file in any code editor and the compiler needs to be installed on your platform now here you can see the syntax of the typescript programming so here we have the very message string which says welcome to Eddie Rica and then we have just used the console dot log and printed the message here now as soon as you compile this it’ll generate the JavaScript code and give you the output as this string which is welcome to Eddie Rica so here you can see the difference in the JavaScript code we do not have message colon string this is how we are representing the string in typescript so now that you know what is typescript let’s see why we need it actually now moving on to why do we use type strip there are different reasons why a JavaScript developer should consider using typescript first is using the new features of ECMAScript so typescript supports the new ECMAScript standards and transpile them to ECMAScript targets of your choice so you can use features of es 2015 and beyond like modules lambda functions classes the spread operator restructuring etc not just that there’s also another feature as the static typing now javascript is dynamically type and it does not know what type of variable is until it is actually instantiated at runtime now typescript adds type support to the JavaScript next up is the type inference now typescript makes typing a bit easier and a lot less explicit by the usage of type inference even if you don’t explicitly type the types they are still there to save you from doing something which otherwise would result in a runtime error Longinus tag there’s also better IDE support so the development experience with typescript is a great improvement over JavaScript there is a wide range of ites that have excellent support for typescript like the visual studio and vs code then we have Adams sublime and IntelliJ or the webstorm and then we have these strict null checking.

so errors like you cannot read a property X of undefined as common in JavaScript programming you can avoid most of these kinds of errors since one cannot use a variable that is not known to the typescript compiler and finally we have the interoperability now types trip closely related to javascript so it has great interoperability capabilities but some extra work is required to work with the JavaScript libraries in typescript so this is about why we need to use types trip now let’s talk about some of the features of typescript now talking about features it is actually cross platform so the typescript compiler can be installed on any operating system such as Windows Mac OS and Linux then it is also object-oriented so type Street provides features like classes interfaces and modules thus it can write object-oriented code for client-side as well as server-side development not just that we have the static type checking and typescript uses static typing and helps type checking at compile time so you can find errors while writing the code without even running the script now along with that you also optional static typing now it allows optional static typing in case you are using the dynamic typing of JavaScript next up we have the Dom manipulation so you can use typescript to manipulate the Dom for adding or removing elements and finally we have the es6 features so typescript includes most features of planned ECMAScript 2015 such as class interface arrow functions etc now these were some of the features of typescript so let’s have a look at the different benefits or the advantages of using typescript now talking about this it is fast simple easy to learn and runs on any browser on javascript engine not just that typescript is similar to JavaScript and uses the same syntax and semantics.

so you would not need extra time to learn this if you are already aware about javascript now this also helps back in developers write front-end code faster also you can call the typescript code from an existing JavaScript code it works with existing JavaScript frameworks and libraries without any issues now the definition file with the dot d dot PS extension it provides support for existing JavaScript libraries like jQuery d3.js etc so typescript code can javascript libraries using type definitions to reveal the benefits of type checking code Auto completion and documentation and existing dynamically typed JavaScript libraries and finally it has features from es6 and es7 that can run in es5 level javascript engines like nord GS so these are some of the features and advantages of using typescript now let’s talk about the different components of typescript there are three different types of components now the first one is language so this comprises of these syntax keyboards and the type annotations then we have the typescript compiler this compiler that is DTSC converts the instructions written in typescript to its javascript equivalent and finally we have the typescript language service the language service exposes an additional layer around the core compiler pipeline editor like applications then the language service supports the common set of typical editor operations.

so these were the three different things included in the components of typescript now how do we actually install typescript now there are two different ways to install typescript tools so the first one is via the NPM which is the node.js package manager command-line tool so you can use the command line as npm install’ g typescript this is the first method the next one is pretty simple all we need to do is install type scrip via visual studio now if you use visual studio vs code ite the easiest way to add to visual studio or vs code is to search and add a package or download from the typescript website also you can download typescript tools for visual studio now all you need to do is just click on the download and install type script in your system so now you know that installing typescript is very easy now talking about the working of typescript even that’s very simple because it’s very similar to how we work in JavaScript now in JavaScript we declare any variable in the following way so here you can see an example as where select value and inside that we will pass any string or any value that we want to but in typescript the declaration is done as so we have the access modifier property or the variable name and then we just take the colon and pass the datatype so suppose I want to give my variable name as selected value so I’ll just take selected value colon and pass the datatype suppose I want to pass the value as string so I’ll just write string here so now here is an example you can see that I have my variable name colon the data type which is string and I’m passing a string value here the next one is an employee ID colon number.

I’m passing numbers here now on compiling this will generate the JavaScript code as their name and then the where employee ID so here we just have the variable name and the value that we have passed it does not show that data type here so this is the difference between these two now talking about the difference let’s get into the details and see what are the main differences between typescript and JavaScript now typescript is a subset of JavaScript and it’s very similar to each other but there are certainly some differences here now typescript is an object-oriented language whereas javascript is actually a scripting language now typescript has a feature known as static typing that we have already discussed about but in JavaScript, we do not have static typing also typescript gives support for modules whereas in JavaScript it does not support any sort of modules and finally the typescript supports optional parameter function but in JavaScript, we do not have the optional parameter function either so these were some of the main differences between typescript and JavaScript and I hope with this you have understood why we need typescript and what it actually does and how similar and different it is from JavaScript.


Please enter your comment!
Please enter your name here