首页 > 解决方案 > 如何将 mongoose.model(xxx, xxx) 导出为 TypeScript 类

问题描述

很想将 mongoose.model(xxx, xxx) 导出为 TypeScript 类?云你帮帮我?非常感谢 !!!!

store_entity.ts
export const StoreSchema: Schema = new Schema({
    name: {
        type: String
    }
}, {
        autoCreate: true,
        versionKey: false
    }
);

StoreSchema.index({ name: 1 }, { unique: true });

export const StoreEntity = mongoose.model('store', StoreSchema, 'store');
test.ts
import { StoreEntity } from './store_entity';

function display(storeEntity: StoreEntity) {
    console.log(storeEntity);
}

但我有错误提示:

'StoreEntity' refers to a value, but is being used as a type here.ts(2749)

在 test.ts 中

标签: typescriptexportmongoose-schema

解决方案


推荐阅读