If you use TypeScript, a useful version of invariant is tiny-invariant:
importinvariantfrom'tiny-invariant';consttitle:any=getValueFromSomewhereUntrusted();// At this point TS will type 'title' as 'any'invariant(typeoftitle==='string');// At this point TS will type 'title' as 'string'
Because of the use of asserts at this source-line you're dropping a hint to the type-engine about what you've called invariant on.
If you use TypeScript, a useful version of invariant is tiny-invariant:
Because of the use of
asserts
at this source-line you're dropping a hint to the type-engine about what you've calledinvariant
on.Yeah, you're right. It's so simple yet useful difference.
Thanks for adding value!