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

1.8: empty enums with same local name incorrectly considered same type #7267

Closed
jeffreymorlan opened this issue Feb 26, 2016 · 6 comments
Closed
Assignees
Labels
Spec Issues related to the TypeScript language specification

Comments

@jeffreymorlan
Copy link
Contributor

In 1.8, if you declare two empty enums with the same local name in different modules, they are assignable, in violation of the spec ("different enum types are not assignable to each other"):

module A { export declare enum Id {} }
module B { export declare enum Id {} }
var a: A.Id;
var b: B.Id;
a = b; // TypeScript 1.7 caught the error here, 1.8 does not.

This bug will not occur (i.e. the error will be correctly reported) if

  • the enums have different local names,
  • one or both of the enums are const, or
  • the enums have named values with different names.
@RyanCavanaugh
Copy link
Member

This is intentional (see #1748) but we need to update the spec

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Spec Issues related to the TypeScript language specification labels Feb 26, 2016
@jeffreymorlan
Copy link
Contributor Author

Can I rely on them being unassignable if I make them const?

@RyanCavanaugh
Copy link
Member

No. You could add some arbitrarily-named member to them, though.

@mhegazy mhegazy removed the Bug A bug in TypeScript label Feb 26, 2016
@zpdDG4gta8XKpMCd
Copy link

does it mean enums are no longer nominal?

@RyanCavanaugh
Copy link
Member

No. For example:

enum A {
    x
}
enum B {
    x
}

// Still an error
var q: A = B.x;

@RyanCavanaugh
Copy link
Member

The spec is now an "archived" artifact and we won't be tracking defects against it anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Spec Issues related to the TypeScript language specification
Projects
None yet
Development

No branches or pull requests

5 participants