Typescript Tutorial

  • - Featured
  • - Table of Contents

TypeScript was initially released on 1 October 2012 and it is a superscript of JavaScript, which when compiled converts into pure JavaScript. TypeScript offers the language with static typing. Microsoft develops and maintains it, as well as being an open-source programming language. TypeScript can be used to create client-side apps as well as apps on the server side. TypeScript is a compiled language that is strongly typed, object-oriented. It was built by Microsoft's Anders Hejlsberg (C # designer).

Features of TypeScript

Check your knowledge:

  1. What is TypeScript and why do we need it?

    TypeScript is a language developed and maintained by Microsoft that is free and open source programming. It is a strict JavaScript superset and introduces to the language optional static typing and object-oriented class-based programming.TypeScript is quite easy to learn and use for developers familiar with C#, Java and all strong typed languages. At the end of day “TypeScript is a language that generates plain JavaScript files.”

  2. What are the benefits of TypeScript?

    TypeScript has following benefits.

    • t helps in code structuring.

    • se class based object oriented programming.

    • mpose coding guidelines.

    • ffers type checking.

    • ompile time error checking.

    • ntellisense.

  3. What are the different components of TypeScript?

    There are mainly 3 components of TypeScript .

    1. Language – The new language is the most important part for developers. The language is made up of new syntax, keywords, and TypeScript can be written.

    2. Compiler – The TypeScript compiler, written in TypeScript, is open source, cross-platform and open specification. Compiler will use JavaScript to compile the TypeScript. And if any, it will also make mistakes. It can also help to combine different files into a single output file and create source maps.

    3. Language Service – TypeScript language service that supports Visual Studio, VS Code, Sublime, TypeScript playground and other editor interactive TypeScript experience.

  4. Does TypeScript support all object oriented principles?

    YES is the answer. Object-oriented programming has four main principles: encapsulation, history, abstraction, and polymorphism. TypeScript can use its smaller and simpler syntax to implement all four of them. Read TypeScript Write Object-Oriented JavaScript.

  5. Which object oriented terms are supported by TypeScript?

    TypeScript supports following object oriented terms.

    • Modules

    • Classes

    • Interfaces

    • Data Types

    • Member functions

  6. What are the disadvantages of TypeScript?

    Well, TypeScript is great but there are some disadvantages as well.

    • TypeScript is another way for JavaScript to be written It doesn't fix JavaScript's issues. It's just making an illusion it does.

    • One more tool to learn.

    • If you want to use some existing JavaScript libraries, TypeScript is based on type specification files.

    • Performance of specification files is a question of how you can be sure that the definitions are right

    • Also a pain area is regular launches of new versions of the JavaScript library. Because if you don't upgrade your form description files, you can't use them instantly.

    • A compile step is required to turn TypeScript into JavaScript to run the request in the browser.

    • Web developers are using JavaScript from decades and TypeScript doesn’t bring anything new.

    • You need to use any file describing a third party library. And not all the library of third parties have available a description archive.

  7. How you can use TS with jQuery, Angularjs and Reactjs

    Angularjs is already integrated with Typescript.So, if you are using Angularjs CLI you don’t need to do anything special. For React and jQuery use Typescript @types and it will install all the dependencies.

    @types/ React @types / jQuery

    Features of TypeScript

    • It is just plain JavaScript.

    • It supports other JavaScript libraries.

    • JavaScript is TypeScript.

    • It is portable.

  8. How to generate TypeScript definition file from any ts file?

    TypeScript definition file can be created via tsc compiler from any ts file. Generating a definition of TypeScript will reusable your TypeScript file tsc --declaration file1.ts

  9. What is tsconfig.json file?

    The presence in a folder of a tsconfig.json file means that a TypeScript project's root is the directory. The file tsconfig.json describes the root files necessary to compile the project and the compiler options available.And we can streamline the building of TypeScript project using this file. A sample tsconfig.json file is shown below.

    { "compilerOptions": { "removeComments": true, "sourceMap": true }, "files": [ "main.ts", "othermodule.ts" ] }

    Within files section, define all the .ts files in the project. And When invoke tsc without any other arguments with the above file in the current directory, it will compile all the files with the given compiler option settings.

  10. What are Modules in TypeScript?

    Modules are the way to organize code in TypeScript. Modules don’t have any features, but can contain classes and interfaces. It is same like namespace in C#.