Skip to content
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

fix(credentials): typing if no modules provided #1188

Conversation

TimoGlastra
Copy link
Contributor

Fixes the typing of the credentials module on the agent when no modules objects has been provided to the agent constructor.

Fixes #1187

@TimoGlastra TimoGlastra requested a review from a team as a code owner January 3, 2023 01:39
Copy link
Contributor

@morrieinmaas morrieinmaas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@berendsliedrecht berendsliedrecht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor comment.

Comment on lines +105 to +106
> = IsAny<CustomModuleType> extends true
? InstanceType<DefaultModuleType['api']>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This confuses me a bit.

It seems like we are checking if the CustomModuleType is supplied and if so, we use the DefaultModuleType['api']. Should that not be CustomModuleType['api'] and if not, maybe we should rename that type if we also use it for custom modules.

Small note, I am not very familiar with the generic module type setup so I might have missed something ;).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is a bit weird. If the custom module type is of type any (which is the case when you provide no modules key) it will pick type any for the credentials module. So what we do here is check if the CustomModuleType is any, and if that is the case we don't want to use it, because it will type the agent.credentials object as any, and we pick the default one. Hope that makes sense?

/**
* Type util that returns `true` or `false` based on whether the input type `T` is of type `any`
*/
export type IsAny<T> = unknown extends T ? ([keyof T] extends [never] ? false : true) : false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this makes me think that this should not work, but it does haha. Quite interesting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this comes straight from Stack overflow. No idea why it works. I can add a link to th so post though

@TimoGlastra TimoGlastra merged commit 541356e into openwallet-foundation:main Jan 4, 2023
@TimoGlastra TimoGlastra deleted the fix/typing-if-no-module-provided branch January 4, 2023 10:28
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.

Types mismatch for credentials property on Agent
3 participants