8000 fix: corrected optional parameter type by bashleigh · Pull Request #144 · auth0/idtoken-verifier · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: corrected optional parameter type #144

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

Conversation

bashleigh
Copy link

Changes

Please describe both what is changing and why this is important. Include:

  • Endpoints added, deleted, deprecated, or changed
  • Classes and methods added, deleted, deprecated, or changed
  • Screenshots of new or changed UI, if applicable
  • A summary of usage if this is a new feature or change to a public API (this should also be added to relevant documentation once released)
  • Any alternative designs or approaches considered

Summary

In the types for the verify method there is an optional param requestedNonce with no default value which is followed by a required parameter cb. This throws an error with tsc TS1016 and is preventing my team from fixing an issue with an alternative package (we decided to use this one to replace it).

To fix this issue I've changed the requestedNonce parameter to be of type string | undefined and made it a required parameter. However I'm not entirely sure if this is the correct solution and perhaps (after look at your codebase) you're looking for requestedNonce or callback which would require 2 different declarations shown below.

Alternative declarations

Based on the codebase I think this is possibly what you're after

verify(token: string, requestedNonceOrCb: string, cb: verifyCallback): any;
verify(token: string, requestedNonceOrCb: verifyCallback): any;

The above then allows requestedNonceOrCb or be either string or verifyCallback and depending on those types (if string) then the cb param is required else is not

References

Please include relevant links supporting this change such as a:

  • support ticket
  • community post
  • StackOverflow post
  • support forum thread

Testing

Please describe how this can be tested by reviewers. Be specific about anything not tested and reasons why. If this library has unit and/or integration testing, tests should be added for new functionality and existing tests should complete without errors.

  • This change adds test coverage

Checklist

@bashleigh bashleigh requested a review from a team as a code owner October 7, 2021 12:07
@bashleigh
Copy link
Author

Realised these are auto generated so I've had to publish a temp package for now so we can fix our issues

@stevehobbsdev
Copy link
Contributor

Thanks @bashleigh, I agree with you that actually we'll need an override declaration here instead of requestedNonce simply being string | undefined. The API + types here is a little smelly as we were trying to patch something while also keeping it backwards compatible. Ideally I'd like to just have token and requestedNonce as an object, which would make the logic here simpler.

If you've already patched it in such a way (maybe in a fork), are you able to update the PR with that change? I think the declarations would be something like:

verify(token: string, requestedNonceOrCb: string, cb: verifyCallback): any;
verify(token: string, cb: verifyCallback): any;

@bashleigh
Copy link
Author

I can however when publishing with microbundle? The types are updated and these changes removed

@stevehobbsdev
Copy link
Contributor

Gotcha.

It looks like we should be able to fix this just with a JSDocs modification but there are (at least) a couple of open bugs that prevent this from working:

I think we're either going to have to turn off types generation (for now) and fix it manually until either type generation can work with this, or we change the API so that we don't need an overload.

A workaround in the meantime would be to just pass undefined for requestedNonce which should get the params in the right order.

Happy to use the workaround for now, and for me to close this while we work out our long-term strategy here?

@bashleigh
Copy link
Author

Thanks for your reply, sure! I am able to pass undefined however the error with the types I wasn't able to ignore (I think it's down to yarn workspaces + webpack but not entirely sure) which affected my build process. For now I can use the alternative lib.

If you need help building a DT lib or other method let me know and I'd be happy to help out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0