Skip to main content

Introduction

  • TypeScript is open source, designed by microsoft.
  • TypeScript means when it's checking to see whether two values are compatible.We wanna understand, how TypeScript does that.
  • TypeScript reduces bugs and improves maintainability when writing JavaScript.

Features

variable typing, function signatures, union and intersection types, type aliases, and generics. Use effective strategies for transitioning your codebase to TypeScript for more robust and scalable applications.

Benefit

  • TypeScript is that it can highlight unexpected behavior in your code
  • lowering the chance of bugs

What are the pros and cons of using TypeScript for its strict typing compared to regular JavaScript?

Yeah, I would look back at this example that we just covered,which kind of illustrates how this regular JavaScript function could be used in a variety of different ways.Sometimes dynamic typing or duck typing,where JavaScript kind of attempts to use a value and it'll try to treat a variable as if things work right up until the moment things blow up or you get an unexpected result.

So for example, you could pass a function for the argument A, or a class, or an HTML DOM node.And where you would start to hit problems is attempting to concatenate these things together.Effectively, you only in JavaScript,know things fail right at the moment where the problematic use happens.

function add(a, b) {
return a + b;
}

What TypeScript is doing for us here is it lets us say,all right, here's the boundary for a unit of code andhere are the constraints that I'm looking to apply.

Error

Argument of type 'string' is not assignable to parameter of type 'number'.

function add(a: number, b: number): number {
return a + b;
}
add(3, "4");

Resources