A common problem that I've come across with some libraries, like grpc
, is that the function interfaces are often the generic any
. Is there a way in TypeScript to override any
with a specific type?
For example, grpc
has the following in the TypeScript definition:
export class ServerUnaryCall {
/**
* Indicates if the call has been cancelled
*/
cancelled: boolean;
/**
* The request metadata from the client
*/
metadata: Metadata;
/**
* The request message from the client
*/
request: any;
private constructor();
/**
* Get the endpoint this call/stream is connected to.
* @return The URI of the endpoint
*/
getPeer(): string;
/**
* Send the initial metadata for a writable stream.
* @param responseMetadata Metadata to send
*/
sendMetadata(responseMetadata: Metadata): void;
}
Any function that is of ServerUnaryCall
will have the same fields, but I want to be able to override request: any
with a specific type.
Is there a way to do this, even if it means rewriting the TypeScript definition to make it possible?