TypeScript Version: 2.8.0-dev.20180228
Search Terms: undefined strictNullChecks bitwise and or
(ref: #22088 (comment))
Code
const enum Flags { A = 2 ** 1, B = 2 ** 2 }
function f(flags?: Flags) {
if (flags & Flags.B) {
}
}
Expected behavior:
No error. & and | work well on undefined values: undefined | 2 is 2, undefined & 2 is 0. Contrast with undefined + 2 which is NaN.
Actual behavior:
src/a.ts(3,9): error TS2532: Object is possibly 'undefined'.