admin管理员组文章数量:1123404
I am using nestJS and prisma ORM for my project. I have task to set proper type to any
type. But i am struggling to do it. For example, i have this part of a function code
async findAllByProjectId(
projectId: string,
count: boolean,
userId?: string,
q?: GetTaskDto,
) {
const timeStamp = Date.now();
console.log('1', Date.now() - timeStamp);
let tasks: Task[];
if (count && projectId) {
return {
count: await getCountTasks(this.prisma, projectId, q),
};
}
if (count && !projectId) {
return {
count: await getCountTasksByWorkerId(this.prisma, userId, q),
};
}
if (!projectId) {
tasks = await getTasksByWorkerId(this.prisma, userId, q);
} else {
tasks = await getTasks(this.prisma, projectId, q);
}
console.log('2', Date.now() - timeStamp);
let data: TaskList[] = tasks.map((e: any) => {
// Get workers data
const workers = e.TaskAssignees.map((taskAssignee: any) => {
return {
id: taskAssignee.assignee.id,
email: taskAssignee.assignee.email,
name: taskAssignee.assignee.name,
roleId: taskAssignee.assignee.roleId,
role: taskAssignee.assignee.Role.name,
};
});
There is statement let tasks: Task[];
so in let data: TaskList[] = tasks.map((e: any)
the e
should be type Task
right? since it iterate the tasks. but when i set e
to type Task
it has so many error. by the way Task is from @prisma/client
Example
Property 'TaskAssignees' does not exist on type '{ id: string; name: string; projectId: string; startDate: Date; endDate: Date; actualStartDate: Date; actualEndDate: Date; calculatedStartDate: Date; duration: Decimal; ... 9 more ...; updatedAt: Date; }'.ts(2339)
or this (but this in next line of the code i show you)
Property 'project' does not exist on type '{ id: string; name: string; projectId: string; startDate: Date; endDate: Date; actualStartDate: Date; actualEndDate: Date; calculatedStartDate: Date; duration: Decimal; ... 9 more ...; updatedAt: Date; }'. Did you mean 'projectId'?ts(2551)
How to handle something like this? It also appear in another code since the getTasks
and getTasksByWorkerId
get call in so many code.
Appreciate it. Thanks
本文标签: typescriptNestJS and Prisma set any to proper typeStack Overflow
版权声明:本文标题:typescript - NestJS and Prisma set `any` to proper type - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736570664a1944768.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论