我的models/areas.ts
文件中有以下内容:
import { Document, model, Schema } from 'mongoose'
import uniqueValidator from 'mongoose-unique-validator'
interface IAreas extends Document {
abstract: string,
code : number,
image : string,
name : string
}
const Areas = new Schema(
{
abstract: {
required: true,
type : String
},
code: {
default: 1,
type : Number
},
image: {
default: '',
type : String
},
name: {
required: true,
type : String,
unique : true
}
}
)
Areas.plugin(uniqueValidator)
const AreasModel = model<IAreas>('areas', Areas)
export { AreasModel, IAreas }
我的controller/areas.ts
文件中有以下内容:
import { AreasModel, IAreas } from '../models/areas'
const getAll = async (): Promise<IAreas[]> => {
try {
const areas = await AreasModel.find({}, '-__v')
return areas
} catch (error) {
console.log('There was a problem trying to get all the areas.')
throw error
}
}
所以,areas
我遇到的问题是变量被推断为任何变量,我不知道为什么,我有其他项目可以正确推断它。
这是我正在使用的版本:
typescript: ^4.1.3
ts-node: ^9.1.1
mongoose: ^5.11.12
@types/mongoose: ^5.10.3
好吧,解决我的问题的是删除@types/mongoose
和@types/mongoose-unique-validator
包。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句