Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow bitwise test on undefined #22230

Closed
ghost opened this issue Feb 28, 2018 · 1 comment
Closed

Allow bitwise test on undefined #22230

ghost opened this issue Feb 28, 2018 · 1 comment
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript

Comments

@ghost
Copy link

ghost commented Feb 28, 2018

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'.
@mhegazy mhegazy added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Feb 28, 2018
@RyanCavanaugh RyanCavanaugh added Declined The issue was declined as something which matches the TypeScript vision and removed In Discussion Not yet reached consensus labels Aug 7, 2018
@RyanCavanaugh
Copy link
Member

It's possible 0 and undefined are intended to have the same semantics in this function, but we really don't know. Arguably the signature should be flags: Flags = 0 if that's the case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants