typescript - 如何将 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 中
解决方案
推荐阅读
- c# - 系统范围的全局列表变量是否存在
- javascript - 打字稿问题:受限制的属性类型不兼容
- r - 更改字符串中间单个字符的大小写
- c++ - 如何确定为 boost::stacktrace::safe_dump_to 分配多少空间?
- java - 如何禁用启用与 IoT 中心的连接?
- symfony - 在 symfony 中添加普通文本类型字段(不是文本框)
- dataframe - 使用 pandas styler 将逐行彩色数据框导出到 excel
- python - 更新 Azure 核心工具后 Python Azure 函数因 AttributeError('__enter__') 失败
- authentication - 我可以从 Blazor 客户端中的 AuthenticationStateProvider 访问我的 ID 令牌吗?
- reactjs - 为什么我会在此组件中获得额外的重新渲染?