I've been pondering about the concept of type guards in TypeScript, particularly regarding their necessity when only one type is defined in a method signature. Most examples in the TypeScript documentation focus on scenarios involving union types, like this:
myMethod(argument: string | number) {
if (typeof argument === 'string') { // do something }
if (typeof argument === 'number') { // do something }
However, I've noticed people utilizing typeof even with strongly typed parameters, as seen here:
myMethod(argument: string) {
if (typeof argument === 'string') { // so something }
What are your thoughts on this approach? How do you handle data validation, especially for information obtained from external sources like API endpoints?