I think you also need to check inside your function that the user specified type is a valid type and then of course check that the user input value corresponds to that specified type. Something similar to this: