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

Google, IBM & Meta Certificates – 40% Off
One Coursera Plus subscription covers most Professional Certificates on Coursera.
Unlock All Certificates
This beginner tutorial explains TypeScript type assertions and type casting, including angle-bracket syntax, double casting with unknown, DOM selection types, and non-null assertions. It uses practical examples and a student coding challenge, with JavaScript familiarity suggested as a prerequisite.

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.