在下面的代码中,为什么result
不是Date
的类型(而不是Date|null
)?
function tester(dates:Date[], x:(_:Date)=>Date|null) {
// the type of result is still "Date|null", even after filtering out the nulls...
let result = dates.map(d => x(d)).filter(d => d !== null);
}
我很快就凑成了sample playground here个.