如何解决缺少试图修补状态的属性
我正在尝试解码 ssl 证书并修补数组属性的状态。这就是我现在正在做的:
状态模型
export interface CertificateStateModel {
certificate: CertificateObject;
certificates: Certificate[];
searchLimitedStateMessage: string;
emptyCertificateMessage: string;
searchTerm: any;
}
@State<CertificateStateModel>({
name: "certificate",defaults: {
certificate: null,certificates: [],searchLimitedStateMessage: SearchMessages.typetoSearch,emptyCertificateMessage: SearchMessages.typetoSearch,searchTerm: null,},})
解码证书的函数
function decodeCert(CertificateObject) {
if (CertificateObject)
for (let entity of CertificateObject) {
const certPem = atob(entity)
console.log(entity)
const cert = pki.certificateFromPem(certPem)
const fingerprint = forge.md.sha1.create().update(forge.asn1.toDer(forge.pki.certificatetoAsn1(cert)).getBytes()).digest().toHex();
const currentDate = new Date();
const daysToExpire = cert.validity.notAfter.valueOf() - currentDate.valueOf();
let certificates = {
name: entity.name,issueDate: cert.validity.notBefore,expiryDate: cert.validity.notAfter,fingerPrint: fingerprint,serialNumber: cert.serialNumber,daysToExpire: daysToExpire / 86400000,}
return certificates;
}
}
获取证书和补丁状态的操作:
@Action(CertificateAction.GetAllCertificates)
getAllCertificates(
ctx: StateContext<CertificateStateModel>,action: CertificateAction.GetAllCertificates
) {
ctx.dispatch(new Busy(true));
return this.svc.getAllCertificates().pipe(
tap((certificate) => {
ctx.patchState({
certificate: decodeCert(certificate)
});
ctx.dispatch(new Busy(false));
console.log(certificate)
},(error: any) => {
ctx.dispatch([
new displayMessage({type: "error",list: [ "Get All Certificates Error",error.error ]}),new Busy(false)
]);
})
);
}
这将返回错误:'certificate.state.ts(22,3): The expected type come from property 'certificate' 它在此处声明为类型 'Partial'
我是 NGXS 的新手,在这里有点迷茫。任何帮助将不胜感激。提前致谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。