I have a generic interface defined as
export interface EventInput {
eventName: string;
metadata?: Record<string, string>;
payload?: Record<string, unknown>;
}
and I create a class
import {EventInput, EventUtilsService} from "@learnapp-co/la-event-utils";
import {UpdateOrganisationInterface} from "./interface";
export interface OrganisationUpdatedPayload {
orgId: string;
pii: string;
}
export class OrganisationUpdatedEventInput implements EventInput {
private readonly eventName = 'OrganisationUpdated';
private readonly payload: OrganisationUpdatedPayload;
constructor(orgId: string, body: UpdateOrganisationInterface, secret: string) {
this.payload = {
orgId,
pii: EventUtilsService.encryptPIIData({
organisationName: body.name,
bank: body.bank,
...(body.revenuePercentage && { revenuePercentage: body.revenuePercentage}),
}, secret),
}
}
public get getEventName(): string {
return this.eventName
}
public get getPayload(): OrganisationUpdatedPayload {
return this.payload
}
}
But I am getting the error
TS2416: Property 'payload' in type 'OrganisationUpdatedEventInput' is not assignable to
the same property in base type 'EventInput'. Type 'OrganisationUpdatedPayload' is not
assignable to type 'Record<string, unknown>'. Index signature is missing in type
'OrganisationUpdatedPayload'.
NOTE: - There can be as many classes as possible for eg OrganisationCreatedeventInput with a different payload which will extend EventInput class.
How can we solve this issue?