[英]Sequelize - Writing model types with .d.ts - everything is optional?
我正在尝试使用.d.ts
文件为我的 JS 中的续集模型编写类型定义。 我有大部分工作,但是,所有属性在Model.create()
中都显示为可选。
index.d.ts
:
interface MyModelSchema extends Model<InferAttributes<MyModelSchema>, InferCreationAttributes<MyModelSchema>> {
id: CreationOptional<string>;
some_required_property: number;
some_optional_property?: number;
}
type MyModel = ModelStatic<MyModelSchema>;
declare const MyModel: MyModel;
index.js
:(MyModel 显示正确的类型)
// Properties on document are correctly marked as required
const document = MyModel.create({
// All properties are optional here
});
事实证明,一直以来我只是在我的jsconfig.json
中缺少"strictNullChecks": true,
的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.