Skip to content

Instantly share code, notes, and snippets.

@marcuzy
Created August 18, 2023 10:35
Show Gist options
  • Save marcuzy/3d6a6001548eaa508bcd9697e8d0608f to your computer and use it in GitHub Desktop.
Save marcuzy/3d6a6001548eaa508bcd9697e8d0608f to your computer and use it in GitHub Desktop.
TS Hell
interface Event<P> {
type: string;
payload: P;
}
type UserCreatedEvent = Event<{
id: string;
fullName: string;
email: string;
role: string;
}>;
export async function produceEvent<T>(topic: Topics, data: Event<T>) {
return channel.publish(topic, '', data);
}
produceEvent<UserCreatedEvent>(Topics.UsersStream, {
type: 'user-updated',
payload: {
id: user._id!.toHexString(), // <--- ругается тут
fullName,
email,
role
}
}).catch(err => console.error('failed to produce event', err));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment