-
Notifications
You must be signed in to change notification settings - Fork 200
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
fix(credentials): typing if no modules provided #1188
Conversation
Signed-off-by: Timo Glastra <timo@animo.id>
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.
LGTM
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.
One minor comment.
> = IsAny<CustomModuleType> extends true | ||
? InstanceType<DefaultModuleType['api']> |
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 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 ;).
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.
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 |
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.
Looking at this makes me think that this should not work, but it does haha. Quite interesting.
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.
Yeah this comes straight from Stack overflow. No idea why it works. I can add a link to th so post though
Fixes the typing of the credentials module on the agent when no modules objects has been provided to the agent constructor.
Fixes #1187