Skip to content

Instantly share code, notes, and snippets.

@bogdanovna
Last active April 19, 2023 07:52
Show Gist options
  • Save bogdanovna/ea9b5458e9f29058d2d22be621983c48 to your computer and use it in GitHub Desktop.
Save bogdanovna/ea9b5458e9f29058d2d22be621983c48 to your computer and use it in GitHub Desktop.
Get value from some record having its key.
export type ValueByKeyType<T extends Record<string, any>, S extends keyof T> = T[S];
/**
* Example of usage
**/
import { ClientProxy } from '@nestjs/microservices';
export type OverrideMicroClient<T extends Record<string, anny>> = Omit<ClientProxy, 'send' | 'emit'> & {
emit<K extends keyof T = keyof T>(pattern: K, ...args: Parameters<ValueByKeyType<T, K>>): ReturnType<ValueByKeyType<T, K>>;
send<K extends keyof T = keyof T>(pattern: K, ...args: Parameters<ValueByKeyType<T, K>>): ReturnType<ValueByKeyType<T, K>>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment