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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: improve PathParams type to support interface #1219
feat: improve PathParams type to support interface #1219
Conversation
6bff640
to
4759feb
Compare
4759feb
to
7656a21
Compare
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 638b92d:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome changes, @kotarella1110! 馃帀
I've added some polishing with the latest commit. Now the tests should pass without issues. Let's wait for that CI before we merge.
@@ -12,7 +12,7 @@ function createRestHandler<Method extends RESTMethods | RegExp>( | |||
) { | |||
return < | |||
RequestBodyType extends DefaultBodyType = DefaultBodyType, | |||
Params extends PathParams = PathParams, | |||
Params extends PathParams<keyof Params> = PathParams, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an interesting pattern.
So, if I read this correctly, by accepting key type as a generic, we are able to limit the known keys to the immediate keys of the current Params
interface. This way the index signature is not ambiguous and instead is limited to the known keys.
Welcome to contributors! 馃帀 |
* feat: improve PathParams type to support interface * test: add * refactor: improve PathParams type * fix: remove optional from properties of PathParams type * chore: name generics, move path params test Co-authored-by: Artem Zakharchenko <kettanaito@gmail.com>
Released: v0.40.0 馃帀This has been released in v0.40.0!
Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |
Passing an interface to the generics of PathParams causes a type error because interface doesn't have an implicit index signature.
I would like to resolve this, but for type safety reasons if you cannot approve this PR please close it 馃檹馃徎