Narrowing of variable types using typeof/instanceof type guards