2024-01-15
1954
#typescript
Oyinkansola Awosan
96803
Jan 15, 2024 ⋅ 6 min read

How to use type guards in TypeScript

Oyinkansola Awosan I'm a fun techie and passionate technical writer interested in data science, machine learning, cloud engineering, and blockchain technologies.

Recent posts:

Crud Rest Api With Node Js Express And Postgresql

CRUD REST API with Node.js, Express, and PostgreSQL

Build a CRUD REST API with Node.js, Express, and PostgreSQL, then modernize it with ES modules, async/await, built-in Express middleware, and safer config handling.

Tania Rascia
Mar 25, 2026 ⋅ 16 min read
the replay march 25

The Replay (3/25/26): Senior dev hiring woes, what AI agents miss, and more

Discover what’s new in The Replay, LogRocket’s newsletter for dev and engineering leaders, in the March 25th issue.

Matt MacCormack
Mar 25, 2026 ⋅ 29 sec read
emmanuel john senior dev hiring

The hidden skills gap in senior dev hiring (and how to screen for it)

Discover a practical framework for redesigning your senior developer hiring process to screen for real diagnostic skill.

Emmanuel John
Mar 25, 2026 ⋅ 12 min read

Does the Speculation Rules API boost web speed? I tested it

I tested the Speculation Rules API in a real project to see if it actually improves navigation speed. Here’s what worked, what didn’t, and where it’s worth using.

Jude Miracle
Mar 24, 2026 ⋅ 10 min read
View all posts

7 Replies to "How to use type guards in TypeScript"

  1. The section on the typeof operator is somewhat incorrect. I can be string, number, boolean, or symbol ALONG WITH function, object, and bigint.

  2. The section “The typeof type guard” may mislead the readers unless the author corrects those type with the lowercased types.

  3. Crazy language… The only way to really check for union typed classInstance is to have some unique filed name in it and do “if (uniqueFieldName in classInstance)”… *blarghhhhh

Leave a Reply

Your email address will not be published. Required fields are marked *

Would you be interested in joining LogRocket's developer community?

Join LogRocket’s Content Advisory Board. You’ll help inform the type of content we create and get access to exclusive meetups, social accreditation, and swag.

Sign up now