[英]Typescript. How to specify a type of a subset of object literal properties?
Specify a type as in 'has property of this type' but may have other properties that we don't care about. 在“具有此类型的属性”中指定一种类型,但可能具有我们不关心的其他属性。
I have the two interfaces: 我有两个界面:
interface IForm {
form: {
name: string;
email: string;
picture: File | null;
}
}
and a sub interface 和一个子界面
interface IUpload {
form {
picture: File | null;
}
}
How would I specify in the IUpload interface that the form
variable should not be that exactly, but rather just have this field, so that the extends
relationship would work in this case. 我将如何在IUpload接口中指定
form
变量不应该完全相同,而应具有该字段,以便在这种情况下extends
关系可以工作。 IForm extends IUpload
? IForm extends IUpload
?
Sorry if I didn't formulate the question correctly. 抱歉,如果我没有正确提出问题。 Thanks in advance!
提前致谢!
I think this might work for you: 我认为这可能对您有用:
interface IForm {
name: string;
email: string;
picture: File | null;
}
Then in your IUpload: 然后在您的IUpload中:
interface IUpload extends Partial<IForm> {
other: things;
}
You're good as it is, I just completed your code and corrected a few typos :) IForm
can extend IUpload
as it has the picture property. 您的状态很好,我刚刚完成了代码,并纠正了一些错字:)
IForm
可以扩展IUpload
因为它具有picture属性。
interface IForm extends IUpload {
form: {
name: string;
email: string;
picture: File | null;
}
}
export interface IUpload {
form:
{
picture: File | null;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.