Trusted answers to developer questions

What is TypeScript?

Get Started With Data Science

Learn the fundamentals of Data Science with this free course. Future-proof your career by adding Data Science skills to your toolkit — or prepare to land a job in AI, Machine Learning, or Data Analysis.

TypeScript is JavaScript which is designed to scale web applications.

As an object-based scripting language, JavaScript is designed by Netscape in 1995. It has an open standard (ECMAScript) and a huge developer community.

TypeScript is an object-oriented language designed by Microsoft in 2012. It is a superset of JavaScript and can be used both a language and a set of tools. It provides optional static typing, which can help to catch errors as they appear making it ideal for large team collaborations.

svg viewer

Advantages

  • TypeScript can point out compilation errors at the time of development.

  • It, as mentioned above, offers static typing which allows catching type errors at compile time and therefore gives a less painful development experience.

  • It is great for large team collaborations.

svg viewer
  • Perhaps the biggest feature that TypeScript provides is type-checking, which can prevent bugs such as the one below:
// TypeScript
function fetchUserID(isUser: boolean) : string {
if (isUser) {
return '94321';
}
return 'username not present';
}
// throws: error TS2345: Argument of type '"true"'
// is not assignable to parameter of type 'boolean'.
let userId = fetchUserID('true');

In the above code, we are passing a string to fetchUserID() function which is expecting a boolean variable. So, it will throw an exception:

Argument of type true is not assignable to the parameter of type boolean.

Sections of TypeScript

TypeScript has the following three sections:

Language: It is an object-oriented language which can be broadly divided into three things:

  • Syntax
  • Keywords
  • Type Annotations

TypeScript compiler: Translates the instructions written in TypeScript to JavaScript.

TypeScript language service: Supports editor operations such as:

  • Statement completion
  • Code formatting
  • Colorization
svg viewer

RELATED TAGS

web development
typescript
javascript
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?