Skip to content

Allow bitwise test on undefined #22230

Closed
Closed
@ghost

Description

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'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DeclinedThe issue was declined as something which matches the TypeScript visionSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions