How to always get the correct variable type