fix(TranslatePipe): handle non string input #893
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I didn't see a contributing guideline and I wasn't sure if I sure file a bug for this/wanted to start more of a discussion about how TranslatePipe should handle non-string input.
Preface
I write shared components for other teams to use (think asset kit), and don't have strict control over inputs. We can put in arg validation as needed but I did run into a case that IMO the TranslatePipe should handle on its own.
Problem
TranslatePipe throws a
Parameter "key" required
error fornumber
type input. IMO this could just return back the number that was passed in, curious on others' opinions?Example
We have a shared filtering/searching component that displays a list of filter labels the user can select from such as:
The basic replication code boils down to:
Which throws the
Parameter "key" required
error.Solution
Return back the original
query
arg if it is falsey or the.length
call is falesy.Discussion
Curious if others agree if this should be the functionality or if I have to resort to coercing all inputs to strings in my components.
@ocombe