In my application, I have a class used for the database and a type received from the frontend.
The database class structure is as follows:
@ObjectType()
@Entity()
export class Task {
@Field(() => Int)
@PrimaryKey()
id!: number;
@Field(() => String)
@Property({ type: 'date' })
createdAt = new Date();
@Field(() => String)
@Property({ type: 'date', onUpdate: () => new Date() })
updatedAt = new Date();
@Field()
@Property({ type: 'text' })
name!: string;
@Field(() => String)
@Property({ type: 'date' })
alertAt = new Date();
@Field(() => Date)
@Property({ type: TimeType})
from: TimeType;
@Field(() => Date)
@Property({ type: TimeType})
to: TimeType;
@Field(() => Boolean)
@Property({ type: 'boolean' })
isDaily: boolean;
}
The type received from the frontend is defined as:
type TaskInput = {
id: number,
from: Date,
to: Date,
daily: boolean,
alertAt: Date
}
When trying to update a Task object with TaskInput values, I encounter the error:
async updateTask(taskInput: TaskInput)
const task = await em.findOneOrFail(Task, { id: taskInput.id })
Object.entries(taskInput).forEach(([key, value]) => {
if(value){
task[key] = value;
}
})
}
However, the error message displays:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Task'.
No index signature with a parameter of type 'string' was found on type 'Task'.
How can I address this issue?