【发布时间】:2020-08-03 14:42:58
【问题描述】:
我有一个简单的 Nest js 服务,如下所示:
import { Injectable } from '@nestjs/common';
import { Model } from 'mongoose';
import { InjectModel } from '@nestjs/mongoose';
import { Collection } from './interfaces/collection.interface';
import { CollectionDto } from './dto/collection.dto';
import { COLLECTION } from '../constants';
@Injectable()
export class CollectionsService {
constructor(
@InjectModel(COLLECTION) private readonly collectionModel: Model<Collection>
) {}
async getAllCollections(): Promise<Collection[]> {
const collections = await this.collectionModel.find().exec();
return collections;
}
async addCollection(collectionDto: CollectionDto): Promise<Collection> {
const newCollection = await this.collectionModel(collectionDto);
return newCollection.save();
}
}
代码运行良好,但我收到 tslint 警告 ts(2348)。有人知道如何以不同于使用// @ts-ignore 规则的方式解决它吗?
【问题讨论】:
-
将光标悬停在错误上时按 alt+F8 应该会给出原因
-
它给了我同样的信息
Value of type 'Model<Collection, {}>' is not callable. Did you mean to include 'new'?ts(2348)
标签: mongodb typescript mongoose nestjs tslint