vendredi 28 octobre 2022

Different interfaces in Typescript Factory

I have a factory like that:

@Injectable()
export class JobApiFactoryService
  implements ApiServiceFactoryInterface<JobApiPayloads>
{
  public constructor(
    private readonly createApplicationActivityService: CreateApplicationActivityService,
    private readonly createActivityService: CreateActivityService
  ) {}

  public async execute(
    payload: JobApiPayloads,
    action: ApiNamesEnum
  ): Promise<void> {
    switch (action) {
      case ApiNamesEnum.CREATE_JOB_APPLICATION_ACTIVITY_EXTENSION:
        await this.createApplicationActivityService.execute(payload);
        break;
      case ApiNamesEnum.CREATE_JOB_ACTIVITY:
        await this.createActivityService.execute(payload);
        break;
      default:
        throw new Error("Invalid action");
    }
  }
}

JobApiPayloads:

   export type JobApiPayloads = JobApplicationActivityExtensionPayloadInterface 
  JobActivityExtensionInterface;

createApplicationActivityService it's using JobApplicationActivityExtensionPayloadInterface as type for payload

createActivityService it's using JobActivityExtensionInterface as type for payload

I get this error:

Argument of type 'JobApiPayloads' is not assignable to parameter of type 'JobApplicationActivityExtensionPayloadInterface'.   Type 'JobActivityExtensionInterface' is missing the following properties from type 'JobApplicationActivityExtensionPayloadInterface': jobId, candidate_ids

Aucun commentaire:

Enregistrer un commentaire