[Incorrect Types] Apify JS Client

I am using the API JS client version 2.8.0 to programmatically create a schedule with 1 task action. The code looks like the following
const schedule = await client.schedules().create({
isEnabled: true,
cronExpression,
actions: [
{
type: ScheduleActions.RunActorTask,
actorTaskId: task.id,
},
],
});
const schedule = await client.schedules().create({
isEnabled: true,
cronExpression,
actions: [
{
type: ScheduleActions.RunActorTask,
actorTaskId: task.id,
},
],
});
However, I get a TS error saying that my action object is missing an id field due to the following interface definition:
interface BaseScheduleAction<Type extends ScheduleActions> {
id: string;
type: Type;
}
interface BaseScheduleAction<Type extends ScheduleActions> {
id: string;
type: Type;
}
When I try to supply a value, the operation fails and no task is added but it works when I add a // @ts-ignore statement and omit id entirely. I suspect that the interface definition is incorrect and id should not be required and instead should be generated by Apify. My suspicions are further confirmed by the fact that the network request sent from the client does not include a value for id when adding a task to a schedule in the UI (see attached image)
No description
4 Replies
stormy-gold
stormy-goldOP•2y ago
I found this GitHub PR from September 2022 pointing out the same issue. Would it be possible to get a fix in? https://github.com/apify/apify-client-js/pull/276
GitHub
fix: ScheduleUpdateData type by magne4000 · Pull Request #276 · api...
ScheduleUpdateData enforces id key on actions prop, but it should be optional. Following snippet should be OK: await client.schedule(schedule.id).update({ actions: [{ type: ScheduleActions.Ru...
MEE6
MEE6•2y ago
@Omar Abdelkader just advanced to level 1! Thanks for your contributions! 🎉
stormy-gold
stormy-goldOP•2y ago
My guess is that the value for id should be required when updating an action but not for creating an action -- as I am trying to do in this case
complex-teal
complex-teal•2y ago
Thanks Omar, I'm reporting it

Did you find this page helpful?