Make Event a generic type accepting Kind

This commit is contained in:
Alex Gleason
2023-04-29 21:21:00 -05:00
committed by fiatjaf_
parent 1647601727
commit 9fa554ca8e

View File

@@ -29,23 +29,23 @@ export enum Kind {
Article = 30023 Article = 30023
} }
export type EventTemplate = { export type EventTemplate<K extends number = Kind> = {
kind: Kind kind: K
tags: string[][] tags: string[][]
content: string content: string
created_at: number created_at: number
} }
export type UnsignedEvent = EventTemplate & { export type UnsignedEvent<K extends number = Kind> = EventTemplate<K> & {
pubkey: string pubkey: string
} }
export type Event = UnsignedEvent & { export type Event<K extends number = Kind> = UnsignedEvent<K> & {
id: string id: string
sig: string sig: string
} }
export function getBlankEvent(): EventTemplate { export function getBlankEvent(): EventTemplate<number> {
return { return {
kind: 255, kind: 255,
content: '', content: '',