Class Central is learner-supported. When you buy through links on our site, we may earn an affiliate commission.

YouTube

Type Assertions and Type Casting - Typescript Tutorial for Beginners

Dave Gray via YouTube

Overview

Dive into a comprehensive tutorial on Type Assertions and Type Casting in TypeScript for beginners. Explore the differences between type assertions and type casting, learn how to convert types using assertions, and understand the angle bracket syntax. Discover techniques for narrowing return values, working with DOM selection types, and using non-null assertions. Complete a hands-on student challenge with two solution approaches. Gain valuable insights into TypeScript's type system and improve your coding skills through practical examples and explanations.

Syllabus

Intro
Welcome
Type Assertions vs Type Casting
What are Type Assertions?
Starter Code
Converting Types with Assertions
Angle Bracket Syntax instead of "as"
Narrowing Return Values with Assertions
Caution: Assertions allow mistakes!
Double Casting and the unknown type
DOM Selection Types
Non-Null Assertions
Angle Brackets and the DOM
Student Challenge
Solution 1: Beginners
Solution 2: Type Assertion
13:50 Syntax error: document.getElementById'img' is what is needed if the element has an id set to "img". This does not change the concept I'm discussing. Just tired eyes and a syntax error.

Taught by

Dave Gray

Reviews

Start your review of Type Assertions and Type Casting - Typescript Tutorial for Beginners

Never Stop Learning.

Get personalized course recommendations, track subjects and courses with reminders, and more.

Someone learning on their laptop while sitting on the floor.