Sure I could implement it for everything, but if I am fetching data from an internal/on-prem server and I know the data coming back, should I be type checking the data that is fetched? Are there general rules for making types and when to use types/nested types?
Lets say I have a UI that searches for info based on a phone number or mac address, I would type check the UI input as sort of a sanitization process right? But the data that input fetches does not need to be type checked?
I guess I'm wondering when I should be trying to make intense type checking like so:
type TPhoneNumber = validatePhoneNumber(); // returns string that fits regex for a phone number or something...
type TMacAddress = validateMacAddress(); // similar to above but with regex for mac address...
type TKeyInfo = {
phoneNumber?: TPhoneNumber;
macAddress?: TMacAddress;
}
type TKey =
| (TKeyInfo & { phoneNumber: TPhoneNumber})
| (TKeyInfo & { macAddress: TMacAddress});
type TFormData = {
searchKey: TKey;
...OtherFormInputs...
}
Does this seem like good practice, or is it too verbose and pointless?
I want to have a form input that takes either a phone number string or a mac address string, has at least one but can have multiple (running sql searches based on these 'keys').