Essential Types And Notations 20 exercises

Basic Types in TypeScript

As we've seen, TypeScript will show errors when types don't match.

This set of examples will show you the basic types that TypeScript gives us to describe JavaScript:

let example1: string = "Hello World!";
let example2: string = 42; // red squiggly line under `example2`
let example3:

Loading exercise


00:00 Let's look at all of the basic types that TypeScript gives us to describe JavaScript. Here we have example one, which is typed as a string. We can see that we can use this colon annotation outside of function parameters too, so on variables. And it's saying equals hello world. Here though, in example two, we've got a string

00:19 and it's actually not corresponding with the type that it's associated with. So we can hover over here and we can see that type number is not assignable to type string. So 42 isn't assignable to example two because it's not a string. Same is true down here for this sort of Boolean thing.

00:36 We've also got a symbol down here and a big int, which was introduced to JavaScript relatively recently and TypeScript also covers it too. So your job is to try to solve these errors by changing these annotations here, changing them to what they're supposed to be to describe the things that are being assigned to them.