我正在尝试学习 TypeScript,并且一直在关注 TypeScript 中枚举支持的在线教程示例。对于下面的代码片段:
enum daysoftheweek{
SUN, MON, TUE, WED, THU, FRI, SAT
}
let day:daysoftheweek ;
day = daysoftheweek.FRI; //line 7
if (day === daysoftheweek.MON){
console.log("got to go to work early");
}else{
console.log("I may go late");
}
Run Code Online (Sandbox Code Playgroud)
...我在编译时收到此错误,我不明白为什么:
TS2367:此条件将始终返回“false”,因为类型“daysoftheweek.FRI”和“daysoftheweek.MON”没有重叠。
如果我将第 7 行修改为此,错误就会消失:
day = daysoftheweek.MON;
有人可以解释一下为什么编译会抛出该错误吗?
(我在这个“没有重叠”错误上关注了其他线程,但无法理解这个特定代码片段问题的原因)
我有一个多格式文档查看器,在其中,为了显示 PDF,我使用 PF Extension 的p:documentViewer组件。提供 PDF StreamedContent 的支持 bean 已进行阶段渲染并按预期工作。然而,尽管 PDF 本身渲染得很好,但查看者不会显示其中的数字签名。p:documentViewer使用时需要添加额外的配置吗?这是我的用法:
<pe:documentViewer id="pdfVw" height="600" width="800" value="#{viewerController4.pdfDocumentStream}">
<f:param name="id" value="#{viewerController4.currentDocId}" />
</pe:documentViewer>
Run Code Online (Sandbox Code Playgroud)
提供 PDF 内容的支持 bean 方法:
public StreamedContent getPdfDocumentStream() throws IOException {
FacesContext context = FacesContext.getCurrentInstance();
if (context.getCurrentPhaseId() == PhaseId.RENDER_RESPONSE) {
return new DefaultStreamedContent();
} else {
String id = context.getExternalContext().getRequestParameterMap().get("id");
Doc doc = pdfDocMap.get(id);
return new DefaultStreamedContent(new FileInputStream(new File(doc.getDocPath())), "application/pdf", doc.getDocName());
}
}
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我在 UI 上还有一个功能,用于显示文档的缩略图 - 对于 PDF,我使用 PDFBox 提取第一页并将其转换为 PNG …