4 ms·
I'm sorry to say but... This check won't help with accidental incorrect casts. Typeof in typescript is a pass through for the JavaScript function, so it only re
by slackingoff2017 9y ago
I'm sorry to say but... This check won't help with accidental incorrect casts. Typeof in typescript is a pass through for the JavaScript function, so it only returns what the JS version does.
A check for a string or number will work, but a check against a typescript object or something complex like a union type will just return 'Object'
- spion 9y agoYou can use a tslint rule to block casts. That way you will only be able to use type guards to change the type of something.