In a vanilla NodeJS tutorial I noticed the instructor always trying to define his variables in a way to guarantee no surprising assignments or values such as this one:
p.name = typeof (coinPair.name.toUpperCase()) === 'string' ? coinPair.name.toUpperCase() : false
I started to use this method in many of my codes to sort of guarantee if the value is not going to be assigned as expected it better be assigned to false (or some other specific default) so that it's easier to detect app crash reasons and avoid unexpected behavior.
When I started to use TypeScript, I realized its' native type safety features, which made me ask: Is the method used above still reasonable when using static strict typing my variables? Will it be useful when TypeScript already will not allow type changes during execution?
A developer I was discussing with was arguing that TypeScript transpiles to JavaScript at the end of the day, and claiming that its' type safety is only useful for debugging and that during runtime it's still javaScript without the TypeScript safety. He claimed that a variable defined as string with TypeScript may still accept a number (perhaps coercing even?).
I am confused now. Should TypeScript type safety measures suffice or I should still use the above method as necessary?