-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stricter typing needed #208
Comments
Hi @juiceo , One common case is to have nested fields, and use a custom |
Thanks for the context @lucaong! I can totally understand the need for this sort of flexibility 👍 I think there is a way to solve this without needing to compromise on that, so we could get the best of both worlds 🤔 I have a suggestion that should work and would support both of these cases - but it would require a breaking change to how the fields are defined. Essentially instead of separate Consider this an RFC:
The Thoughts on the approach? Happy to refine it further if you think it could be worthwhile to explore. I think given a bit more thought, there might also be a way to support this sort of thing without making any breaking changes to the API. |
Hi @juiceo , That said, I think the benefits do not outweigh the cost of introducing such a breaking change. A large percentage of users come from plain JS, and only need the basic I understand the appeal of a strict type design, but that tends to impose a level of complexity (even in the type definitions) that most users are not comfortable with. Again, I do see the appeal of a solid type definition that works well with generics. But also, other users that are into functional programming might wish to have an API made with composable pure functions. Or OOP-inclined developers might want to specify the options as a dedicated class with a fluent API. While I do like some of these ideas myself, I think that a foundational building block library like That said, I’d be super happy to see a stricter adapter designed on the basis of your idea, wrapping the more “type lenient” |
Makes perfect sense 👌 As it happens I already implemented this sort of adapter for minisearch for our use case, so I could definitely take a look at putting out a PR for it. What do you think would be the best way to introduce the possibility to opt in to stricter typing? Is there a way it could be included in the core package or do you see something like this as belonging more to a 3rd party package? (TBH not really excited about the prospect of becoming an npm package maintainer 😄 ...but if you feel there's a way we can make it part of the core package would be happy to take a stab!) |
In the short term I feel more like it should belong to a 3rd party package. One alternative could be to introduce a (much needed) "how to" section in the docs, explaining how to do various things, including "how to make the options more type safe with TypeScript". In this case there would be no additional package, but rather some instructions. If you want, you can provide some example code in this thread, and I will copy it to the "How To" section when I create one. I will evaluate what would it mean to support the type safe but more verbose way of specifying options on top of the current way. If it does not involve too much additional code to maintain and test, nor too much complexity, it might be worth adding this to the core. |
Alright, I'll see if I can make something happen with that 👍 |
Hi! I like the library, but would need it to have some stricter typing to be usable in production applications.
Would it be possible to modify the
SearchOptions
andOptions
types so that we pass in a generic type argument for the shape of the rows, and restrict thefields
and other similar properties to only keys of the row type?A simple implementation would look like this:
The text was updated successfully, but these errors were encountered: