类型';任务';不满足约束';文档'; [英] Type 'Task' does not satisfy the constraint 'Document'
本文介绍了类型';任务';不满足约束';文档';的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Nestjs和MongoDB创建API。tasks.service.ts,尝试创建getall终结点,但得到TypeScript错误:
Type 'Task' does not satisfy the constraint 'Document'. Type 'Task' is missing the following properties from type 'Document': increment, model, $isDeleted, remove, and 51 more.
tasks.service.ts
import { Injectable, HttpStatus } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { Task } from './dto/task.inferface';
@Injectable()
export class TasksService {
private readonly Tasks: Task[] = [];
constructor(@InjectModel('Task') private readonly TaskModel: Model<Task>) {}
async getAll(): Promise<Task> {
const tasks = await this.TaskModel.find().exec();
return tasks;
}
}
推荐答案
从接口扩展Document类。
import { Document } from 'mongoose';
export interface Task extends Document {
//Task info ...
}
这篇关于类型';任务';不满足约束';文档';的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文