convert to typed value based on prototype