- dynamoose 库为构建模型提供了以下签名:
model: {
<T extends Document>(name: string, schema?: SchemaDefinition | Schema, options?: Partial<import("./Model").ModelOptions>): T & Model<T> & ModelDocumentConstructor<T>;
defaults: any;
};
- TypeScript 文件中的消费按如下方式进行:
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:导出的变量 <x> 具有或正在使用来自外部模块的名称 <y>,但无法命名
但是接口本身没有导出,所以不能导入。