Coming from #32992 (review)...
Problem
Currently, the object returned by validate is just a Record<string, string>, but we know that the return type should be a map of formInputID: translationKey, so we're missing an opportunity to be precise and expressive with our type definitions. Some more specific problems with this implementation are:
- It's easy to put whatever string you want in the return type (for example, I was mistakenly using
translate(translationKey), when all I needed was translationKey).
- If you use a constant for a form inputID (which is a good practice), then you'll get a type error referencing it in the return type of validate and have to cast it to a normal string (with
as string).
Solution
Implement the fixes @blazejkustra laid out here.
Coming from #32992 (review)...
Problem
Currently, the object returned by
validateis just aRecord<string, string>, but we know that the return type should be a map offormInputID: translationKey, so we're missing an opportunity to be precise and expressive with our type definitions. Some more specific problems with this implementation are:translate(translationKey), when all I needed wastranslationKey).as string).Solution
Implement the fixes @blazejkustra laid out here.