我有扩展子类型的联合示例:
type TypeA = {|
type: "a",
value: number,
|};
type TypeB = {|
type: "b",
value: Array<number>,
|};
type SuperType =
| TypeA & {|
color: string,
|}
| TypeB;
function test(val: SuperType): void {
if (val.type === "b") {
// Flow should probably know that val.value is an array here
console.log(val.value.length);
}
}
但是,最后,当我尝试利用Disjoint Unions with exact types时,它失败了:
20: console.log(val.value.length);
^ Cannot get `val.value.length` because property `length` is missing in `Number` [1].
References:
3: value: number,
^ [1]
我无法弄清楚Flowtype是不支持这个还是我做错了什么。这发生在Flow 0.66上。请注意,如果我删除{| color: string |}
位,则此方法有效。
答案 0 :(得分:0)
在library(lubridate)
# A small function that prints the date
# of the last month in the YYYY-MM format
last_month <- function(d = today()) {
day(d) <- 1
month(d) <- month(d) - 1
format(d, "%Y-%m")
}
# lets try it
last_month()
#> [1] "2018-02"
file <- "Fin_report.xlsx"
# replace the .xlsx with -YYYY-MM.xlsx
file2 <- gsub("\\.xlsx$", paste0("-", last_month(), ".xlsx"), file)
file2
#> [1] "Fin_report-2018-02.xlsx"
中,使用点差运算符SuperType
代替交集运算符...
:
&