Type Assertions & Type Casting | Typescript Tutorial for Beginners

Dave Gray โ€ข November 4, 2022
Video Thumbnail

About

Web Development tutorials with full courses on HTML, CSS, JavaScript, React, Node.js and more! My goal is to help you learn how to build the web. Teaching helps me learn, too. I work full-time as a Solutions Architect / Developer and part-time as a university web dev instructor. Thank you for subscribing, supporting my channel and sharing the videos you think may help others. Keep striving for progress over perfection. And a little progress every day goes a very long way. Milestones: July 20, 2020 - 1st video Jan 1, 2021 - 1k subs April 2021 - 4k watch hours Nov 2021 - 10k subs Jan 21, 2022 - Video at 100k views Feb 16, 2022 - 100k watch hours Feb 19, 2022 - 1m views Dec 13, 2022 - 100k subs Dec 2022 - Over 1m views in 1 month April 7, 2023 - 10m views May 26, 2023 - 1m watch hours Sept 22, 2023 - Video at 1m views Dec 25, 2023 - 250k subs

Video Description

Web Dev Roadmap for Beginners (Free!): https://bit.ly/DaveGrayWebDevRoadmap Learn Type Assertions & Type Casting in this Typescript tutorial for beginners. Learn more about type assertions and type casting and complete a Typescript student challenge in detailed TS tutorial. ๐Ÿš€ Become a full-stack web dev with Zero To Mastery Courses: - The Complete Web Developer: https://bit.ly/WebDevMaster - Master the Coding Interview: https://bit.ly/FAANGInterview - Junior to Senior Dev Roadmap: https://bit.ly/WebDevRoadmap-JrtoSr ๐Ÿšฉ Subscribe โžœ https://bit.ly/3nGHmNn ๐Ÿ“ฌ Course Updates โžœ https://courses.davegray.codes/ โ“ Questions - Please post them to my Discord โžœ https://discord.gg/neKghyefqh โ˜• Buy Me A Coffee โžœ https://www.buymeacoffee.com/davegray ๐Ÿ‘‡ Follow Me On Social Media: Github: https://github.com/gitdagray Twitter: https://twitter.com/yesdavidgray LinkedIn: https://www.linkedin.com/in/davidagray/ ๐Ÿ”— All Resources for this Typescript Course: https://github.com/gitdagray/typescript-course ๐Ÿ”— Playlist for this Typescript Course: http://bit.ly/3GcNJ78 Type Assertions & Type Casting | Typescript Tutorial for Beginners (00:00) Intro (00:05) Welcome (00:28) Type Assertions vs Type Casting (01:18) What are Type Assertions? (01:58) Starter Code (03:44) Converting Types with Assertions (04:53) Angle Bracket Syntax instead of "as" (05:55) Narrowing Return Values with Assertions (08:37) Caution: Assertions allow mistakes! (10:07) Double Casting and the unknown type (12:03) DOM Selection Types (16:19) Non-Null Assertions (17:43) Angle Brackets and the DOM (18:14) Student Challenge (21:27) Solution 1: Beginners (24:13) Solution 2: Type Assertion Corrections: (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. ๐Ÿ“š Suggested Pre-requisites for this Typescript course: ๐Ÿ”—JavaScript for Beginners full course: https://youtu.be/EfAl9bwzVZk ๐Ÿ“š Tutorial References: ๐Ÿ”— Typescript Official Website: https://www.typescriptlang.org/ ๐Ÿ”— Anders Hejlsberg, Creator of Typescript and C# Interview: https://dev.to/destrodevshow/typescript-and-c-both-created-by-the-same-person-named-anders-hejlsberg-42g4 ๐Ÿ”— Stackoverflow Survey Results: https://survey.stackoverflow.co/2022/#technology-most-popular-technologies ๐Ÿ”— MDN - Static Typing: https://developer.mozilla.org/en-US/docs/Glossary/Static_typing ๐Ÿ”— MDN - Dynamic Typing: https://developer.mozilla.org/en-US/docs/Glossary/Dynamic_typing ๐Ÿ”— MDN - Type Coercion: https://developer.mozilla.org/en-US/docs/Glossary/Type_coercion ๐Ÿ”— TS Type Assertions: https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#type-assertions โš™ Web Dev Tools: ๐Ÿ”— Chrome Browser: https://www.google.com/chrome/ ๐Ÿ”— Visual Studio Code (VS Code): https://code.visualstudio.com/ ๐Ÿ”— Node.js & npm: https://nodejs.org/ ๐Ÿ”— Live Server VS Code Extension: https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer Was this Typescript Assertions and Type Casting tutorial helpful? If so, please share. Let me know your thoughts in the comments. #typescript #assertions #casting

You May Also Like

Essential Gaming PC Parts

AI-recommended products based on this video

Loading...
Beelink SER3 Mini Desktop PC with AMD Ryzen 3 3200U 2C/4T, 16GB DDR4 500GB PCIE3.0 X4 SSD, Dual Display Output, WiFi6/BT5.2 W-11 Pro Mini Gaming Computer

Beelink SER3 Mini Desktop PC with AMD Ryzen 3 3200U 2C/4T, 16GB DDR4 500GB PCIE3.0 X4 SSD, Dual Display Output, WiFi6/BT5.2 W-11 Pro Mini Gaming Computer

(239)
$459.00
FREE delivery Sat, Jan 3
Loading...
Beelink SER3 Mini PC, AMD Ryzen 3 3200U(14nm, 2C/4T) up to 3.5GHz, Mini Gaming Computer 16GB DDR4 RAM 500GB PCIE3.0 X4 SSD, Micro PC 4K@60Hz Dual Display, Mini Computer WiFi6/BT5.2/HTPC/W-11 Pro

Beelink SER3 Mini PC, AMD Ryzen 3 3200U(14nm, 2C/4T) up to 3.5GHz, Mini Gaming Computer 16GB DDR4 RAM 500GB PCIE3.0 X4 SSD, Micro PC 4K@60Hz Dual Display, Mini Computer WiFi6/BT5.2/HTPC/W-11 Pro

(1,251)
$329.00
FREE delivery Sat, Jan 3
Loading...
Beelink SER3 Mini PC, AMD Ryzen 3 3200U(up to 3.5GHz) 2C/4T, Mini Computer 16GB DDR4 RAM 500GB SSD, Mini Desktop Computer 4K@60Hz Dual HDMI Display WiFi6/BT5.2/WOL/HTPC/W-11 Pro

Beelink SER3 Mini PC, AMD Ryzen 3 3200U(up to 3.5GHz) 2C/4T, Mini Computer 16GB DDR4 RAM 500GB SSD, Mini Desktop Computer 4K@60Hz Dual HDMI Display WiFi6/BT5.2/WOL/HTPC/W-11 Pro

(815)
$329.00
FREE delivery Sat, Jan 3
50+ bought in past month
Loading...
EVGA GeForce GTX 1660 Ti XC Ultra Gaming, 6GB GDDR6, HDB Fan Graphics Card 06G-P4-1267-KR

EVGA GeForce GTX 1660 Ti XC Ultra Gaming, 6GB GDDR6, HDB Fan Graphics Card 06G-P4-1267-KR

(1,163)
$1,970.86
FREE delivery Feb 26 - Mar 5
Loading...
CORSAIR Hydro X Series iCUE Link XH405i Custom Cooling Kit โ€“ Hardline Water Cooling Loop โ€“ XC7 Elite CPU Water Block โ€“ XD5 Elite D5 Pump Res โ€“ XR5 360mm Radiator โ€“ 3X QX120 RGB Fans

CORSAIR Hydro X Series iCUE Link XH405i Custom Cooling Kit โ€“ Hardline Water Cooling Loop โ€“ XC7 Elite CPU Water Block โ€“ XD5 Elite D5 Pump Res โ€“ XR5 360mm Radiator โ€“ 3X QX120 RGB Fans

(235)
$879.99
FREE delivery Sun, Aug 24
Loading...
Logitech G203 Wired Gaming Mouse, 8,000 DPI, Rainbow Optical Effect LIGHTSYNC RGB, 6 Programmable Buttons, On-Board Memory, Screen Mapping, PC/Mac Computer and Laptop Compatible - Black
Best Seller

Logitech G203 Wired Gaming Mouse, 8,000 DPI, Rainbow Optical Effect LIGHTSYNC RGB, 6 Programmable Buttons, On-Board Memory, Screen Mapping, PC/Mac Computer and Laptop Compatible - Black

(17,871)
$27.98$22.38
FREE delivery Tue, Oct 14 on your first order
500+ bought in past month
Loading...
CORSAIR iCUE Link XD5 RGB Elite LCD Pump-Reservoir Unit - D5 PWM Pump - 480x480 IPS LCD Screen - 22 Addressable RGB LEDs - 440ml Nylon Reservoir - White

CORSAIR iCUE Link XD5 RGB Elite LCD Pump-Reservoir Unit - D5 PWM Pump - 480x480 IPS LCD Screen - 22 Addressable RGB LEDs - 440ml Nylon Reservoir - White

(17)
$379.99
FREE delivery Sun, Aug 24
Loading...
CORSAIR iCUE Link XC7 RGB Elite CPU Water Block - Transparent Flow Chamber - 24 RGB LEDs - Fits Intelยฎ LGA 1700, AMDยฎ AM5 and Older - White

CORSAIR iCUE Link XC7 RGB Elite CPU Water Block - Transparent Flow Chamber - 24 RGB LEDs - Fits Intelยฎ LGA 1700, AMDยฎ AM5 and Older - White

(56)
$149.99$125.33
FREE delivery Sun, Aug 24
Loading...
CORSAIR Hydro X Series iCUE Link XH405i Custom Cooling Kit โ€“ Hardline Water Cooling Loop โ€“ XC7 Elite CPU Water Block โ€“ XD5 Elite D5 Pump Res โ€“ XR5 360mm Radiator โ€“ 3X QX120 RGB Fans

CORSAIR Hydro X Series iCUE Link XH405i Custom Cooling Kit โ€“ Hardline Water Cooling Loop โ€“ XC7 Elite CPU Water Block โ€“ XD5 Elite D5 Pump Res โ€“ XR5 360mm Radiator โ€“ 3X QX120 RGB Fans

(235)
$879.99
FREE delivery Sun, Aug 24
Loading...
HyperX CloudX Stinger 2 Core - Gaming Headset for Xbox, Lightweight Over-Ear headsets with mic, Swivel-to-Mute Function, 40mm Drivers - White

HyperX CloudX Stinger 2 Core - Gaming Headset for Xbox, Lightweight Over-Ear headsets with mic, Swivel-to-Mute Function, 40mm Drivers - White

(5,595)
$44.99
PrimeFREE delivery Sat, Jun 14