Compare enums semi-structurally.#6036
Conversation
1. Unqualified names must match. 2. Target contains members with same names as all source members.
|
Could you add some tests with |
There was a problem hiding this comment.
You need to use hasProperty here
There was a problem hiding this comment.
what I meant is it that with this code
enum A { X }
enum A { Y }
let a = A.X | A.Y // A has both X and Yyou will see only X member, but you won't see Y since you are using one declaration to obtain property names.
There was a problem hiding this comment.
Is there already a right way to get all members of enums? Otherwise I'll need to write getDeclarationsOfKind and then look at all members from those symbols.
There was a problem hiding this comment.
well, you already have types on hand, so you can get its members that has flag SymbolFlag.EnumMember. Open question is if you need to pay attention to the order of member since it can directly affect values of enum members
There was a problem hiding this comment.
I believe in the discussion around #1748 last week, we decided to ignore values of members. So as long as the enums are not const, we will just check for existence of matching property names.
There was a problem hiding this comment.
The type object for enums don't actually have members defined, so there are no members to check for EnumMember.
There was a problem hiding this comment.
symbol for a enum type should have exports that contain all enum members
There was a problem hiding this comment.
resolveStructuredTypeMembers(enumType).members should do the trick
Use getTypeOfSymbol >> resolveStructuredTypeMembers >> properties instead of looking at declarations.
There was a problem hiding this comment.
Sorry, given what Wesley said, I think it was correct to do what you were doing before when creating the map. If member.name isn't astring, how is this working? Don't you need member.name.text?
There was a problem hiding this comment.
member.name is a string:
function Symbol(flags: SymbolFlags, name: string) {
this.flags = flags;
this.name = name;
this.declarations = undefined;
}There was a problem hiding this comment.
Ah, it's the symbol, not the member itself. This is fine then.
|
@vladima any more comments? |
There was a problem hiding this comment.
lift it to a variable so it is not refetched on every iteration (cost of it is probably low but still)
|
👍 after minor nit from comment is addressed |
Compare enums semi-structurally.
|
Keywords: enum identical names relate related to assignable compatible compatibility |
Fixes #1748.