model: {
<T extends Document>(name: string, schema?: SchemaDefinition | Schema, options?: Partial<import("./Model").ModelOptions>): T & Model<T> & ModelDocumentConstructor<T>;
defaults: any;
};import * as dynamoose from 'dynamoose';
...
const ExampleRepository = dynamoose.model(
schemaName,
ExampleSchema,
);
export default ExampleRepository;Exported variable 'ExampleRepository' has or is using name 'ModelDocumentConstructor' from external module ".../node_modules/dynamoose/dist/index" but cannot be named.有关SO的类似问题的其他答案将建议进口ModelDocumentConstructor。TS4023: Exported Variable has or is using name from external module but cannot be named
但是,接口本身没有导出,因此不能导入。
发布于 2020-05-29 20:59:24
由于没有导出ModelDocumentConstructor,所以我实现了以下解决方案作为解决方案。创建第二个要导出的包装对象,该对象包含所需的方法。
例如:
const Model = dynamoose.model('MyObj', Schema, {
create: false,
update: false,
});
async function add(obj: {}) {
try {
await Model.create(obj);
} catch (e) {
console.error(e);
}
}
async function findMany(obj: { [key: string]: any }) {
try {
return await Model.batchGet(obj);
} catch (e) {
console.error(e);
}
}
...
export const myObjDb = {
find,
findMany,
add,
remove,
update,
updateMany,
};
发布于 2020-06-02 03:41:39
从文档中看,它说类型记录支持处于beta版,但npm安装--保存"dynamoose@beta“不起作用。
是最新的版本支持类型抄本,或非常脆弱。
发布于 2020-06-18 08:51:52
如果在"declaration": true文件中设置了tsconfig.json选项,则会出现此问题。如果该项目不需要禁用它,将解决问题。
我已经在动态存储库中填写了一个bug报告,希望它能在下一个版本中得到修复。
https://stackoverflow.com/questions/61963486
复制相似问题