Closed PhilGarb closed 3 years ago
It has a reasonable default. The expectation is that if you want you're safety you provide the type. Is there a way to get type safety without the default and without specifying the type? If we remove the default would that be better?
Thank you for the quick response. Providing a reasonable default is very sensible and I would not remove it. I think the main issue is, that an object with a nested array like above needs to be mapped over to get the key that should be matched. This is what the docs describe. This does however produce an array of strings and not just strings.
I had another look and managed to solve my error by simply creating a union type of string
and Array<string>
. Please have a look at PR #117. I think this should fix the issue and not interfere with anything else.
match-sorter
version: 6.0.1node
version: 15.0.1Relevant code or config
What you did: I followed the documentation. The above example is straight from the docs.
What happened: TypeError
Reproduction repository: https://codesandbox.io/s/goofy-hodgkin-nm8u5?file=/src/index.ts
Problem description: I have a data structure with a nested array of objects that I would like to also be match and sortable. The code provided in the documentation worked before 6.0.0 and still works, but now Typescript complains. I guess there is just a small mismatch in the provided types for this use case.
Suggested solution:
matchSorter
seems to handle the use case just fine. Maybe it is just the accepted type that needs to be adjusted. I think below might be the place whereItemType
is specified as string, but it should actually also be an array of strings. I am not sure, whether this would be sufficient though.https://github.com/kentcdodds/match-sorter/blob/0f731a1646820df2d47b153a575e16d3dc4c3356/src/index.ts#L77-L81