Open brandonw opened 1 month ago
@brandonw You may try typing watch
as InstanceType<typeof Consul.Watch>
.
I overlooked the possibility of using shortcuts for these instance types. If needed, I’ll be happy to make further adjustments.
@UNIDY2002 that works just as needed, thanks!
Another example that may need a different approach is referencing the type of the function args of an instance function consul.health.service()
.
This seems to almost be do-able via Parameters<InstanceType<typeof Consul.Health>['service']>
with the exception that the function is overloaded:
service(options: ServiceOptions): Promise<ServiceResult>;
service(service: string): Promise<ServiceResult>;
I think if there was an additional general case override a la
service(options: ServiceOptions): Promise<ServiceResult>;
service(service: string): Promise<ServiceResult>;
service(service: ServiceOptions | string): Promise<ServiceResult>;
Then it would be possible with a bit of effort?
Then again, there is probably some advanced type magic you can do in order to iterate over the overloads and then grab the first one explicitly, but that is beyond my current capabilities 😁
@brandonw Thank you for your prompt feedback! I agree that referencing these types can be quite complex, creating obstacles for users. I’m exploring ways to implement shortcuts for these internal types to improve usability.
Additionally, since these type definitions are still in a relatively immature state, I welcome any further feedback regarding any inconvenient usage you may encounter!
I am having difficulties consuming the new types. One specific example is I save a
Watch
instance created viaconsul.watch()
, but cannot properly specify the type in the class definition.As someone who only has some Typescript experience, I think the problem may be that the new declaration files do not specify namespaces? This causes any top-down usage to be typed, but no types to be exported other than
lib/index.d.ts
's export ofConsul
.So when typing things: