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

narrowing in switch doesn't work with ambient enums #16977

Open
zpdDG4gta8XKpMCd opened this issue Jul 6, 2017 · 2 comments
Open

narrowing in switch doesn't work with ambient enums #16977

zpdDG4gta8XKpMCd opened this issue Jul 6, 2017 · 2 comments
Labels
Bug A bug in TypeScript
Milestone

Comments

@zpdDG4gta8XKpMCd
Copy link

declare global {
    module g.m {
        enum E { A, B }
    }
}
declare var x: g.m.E;
declare function never(never: never): never;
function fn() {
    switch (x) {
        case g.m.E.A: return 1;
        case g.m.E.B: return 2;
        default: return never(x); // <-- x expected to be never, actual g.m.E
    }
}
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Jul 6, 2017
@mhegazy mhegazy added this to the TypeScript 2.7 milestone Nov 21, 2017
@zpdDG4gta8XKpMCd
Copy link
Author

might be related: #20375

@mhegazy mhegazy modified the milestones: TypeScript 2.7, TypeScript 2.8 Jan 9, 2018
@Goodwine
Copy link

Goodwine commented Jan 31, 2018

The compiler is happy if you declare what possible numbers can these enum have.

module g.m {
  enum E { A = 3, B = 7}
}

Test code

I also found this to be annoying and I wish the compiler could at least do this for switches :(
I first thought this could be a bug on but I guess it's not angular/clutz#663

IIUC when this bug gets fixed, then it should be fixed for any kind of enums, not just numeric enums, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants