Skip to content

Compiler hangs on union of enums with a large number of elements #12535

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

Closed
NoelAbrahams opened this issue Nov 28, 2016 · 2 comments
Closed

Compiler hangs on union of enums with a large number of elements #12535

NoelAbrahams opened this issue Nov 28, 2016 · 2 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@NoelAbrahams
Copy link

TypeScript Version: 2.1 RC / (Version installed with VS 2017)

Code

namespace enums {

    export const enum A {
        a1,
        a2,
        a3,
       // ... elements omitted for the sake of clarity
        a75,
        a76,
        a77,
    }

    export const enum B {
        b1,
        b2,
       // ... elements omitted for the sake of clarity
        b86,
        b87,
    }

    export const enum C {
        c1,
        c2,
       // ... elements omitted for the sake of clarity
        c210,
        c211,
    }

    export type Genre = A | B | C;
}

type Foo = {
    genreId: enums.Genre;
};

type Bar = {

    genreId: enums.Genre;
};

type FooBar = Foo & Bar;

function foo(so: any) {

    const val = so as FooBar;

    const isGenre = val.genreId;

    return isGenre;
}

Expected behavior:

Compilation in a few hundred milliseconds

Actual behavior:

Compilation took 1 minute 5 seconds for the code sample above (i.e. where the omitted enum elements are filled out exactly.) In the actual code, the build hangs indefinitely.

This bit of code was working fine with TS 2.0.

@ahejlsberg ahejlsberg added the Bug A bug in TypeScript label Nov 28, 2016
@ahejlsberg ahejlsberg self-assigned this Nov 28, 2016
@ahejlsberg
Copy link
Member

This is an issue caused by #11717. We need to deduplicate intersections before we distribute them over union types. Looks like an easy fix.

@ahejlsberg ahejlsberg added the Fixed A PR has been merged for this issue label Nov 28, 2016
@NoelAbrahams
Copy link
Author

@ahejlsberg, not sure if it has any bearing but in the actual problem code every enum value is unique (i.e. the elements of A, B and C do not share any values). I hope that's still okay.

@mhegazy mhegazy added this to the TypeScript 2.1.3 milestone Nov 28, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants