Understanding type compatibility
In this lesson, we'll learn how TypeScript decides whether an item can be assigned to another, i.e. how TypeScript decides whether types are compatible.
We'll cover the following...
Basic type compatibility #
Consider the code below. Hopefully, it is no surprise that TypeScript isn’t happy with the assignment on the last line because the types aren’t compatible.
let firstName: string = "Fred";
let age: number = 30;
firstName = age; // Type 'number' is not assignable to type 'string'.
What about the code below. Will TypeScript be happy with the assignment on the last line?
Access this course and 1400+ top-rated courses and projects.