TypeScript has established itself as the go-to tool for building scalable, maintainable, and efficient applications. Its type system is not only ro...
For further actions, you may consider blocking this person and/or reporting abuse
github.com/ts-essentials/ts-essent...
Great article
Thanks for the kind wordsπ€
Amazing!
Thanks for checking it outππ€
Thanks for sharing
No problem at all. Hope it adds value!ππ
Great series!
You're welcome! Glad you found it useful.ππ€
Great! Thanks!
Thanks for reading and appreciating the effortπ
thanks for sharing a great article.
Thanks for taking the time to read it!π€
Good!
Thanks, appreciate the kind words!π€
Very creative and useful article. Thanks bro....
I'm glad it was useful to you. That's what I aimed for!!π€
Nice article!! I have a question. I'm still figuring out the usefullness of Type Guards, which in principle seems fine, but in practice it seems awkward. The "typeof" operator have been out in the field in many languages and the examples I have seen both in your article and in the TypeScript documentation doesn't explain the need for that Type Guard.
For example: the isString function if the type guard ensures the value is string then why not just return true? At the same time it defeats the purpose to have a function that always returns true. And what would be the behaviour if I call the function with a number?
Just for the sake of understanding I created a test which worked the same with the type guard and without it, so, I can't spot the value of having such syntax.
It's a great question, Juan! Type Guards like
isString
aren't just about returningtrue
orfalse
they narrow down the type of a variable, enabling TypeScript to provide better type-checking and autocomplete support.For example, in your
isString
test:Without the guard, TypeScript wouldn't know
value
is a string, andtoUpperCase()
would throw an error for non-strings.This mechanism shines when working with
unknown
orany
types, union types (string | number
), or complex objects. Guards ensure safety while avoiding redundant casting.Your tests likely work because you're manually ensuring the values match expected types. In dynamic code, where inputs aren't predictable, Type Guards save the day. They're less about "returning true" and more about refining types to avoid runtime errors.
Let me know if you have any other questions...π
The Jollibee bucket price starts at β±350 for the 6-piece Chickenjoy, perfect for sharing with family and friends.
Great Read, thanks for sharing
Great Steps