Emit non-identifier enum member references as typeof parent[some name] #40679
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #40152
What we generate to refer to a non-identifier named enum on
master
,E.1-2
, is syntactically invalid emit.E["1-2"]
would refer to the"1-2"
member of the typeE
(which is the union of all enum members), so doesn't exist (and wouldn't refer to what we wanted if it did). So the best we could do istypeof E["1-2"]
- which looks up the value type ofE
and pulls out the type of the"1-2"
property form it, which, in the case of enums, is fortunately the same as the type provided by theE.1-2
namespace member, so is what we're looking for.This solves the immediate issue brought up by #40152 with a special case in the node builder to build out the access described above, however, generally speaking, the type side of non-identifier-named namespace members are not currently accessible via any syntax means. This is in some ways an oversight - until we gave enum members distinct type identities for literal-typed enums, we had no syntax allowing one to declare a namespace member with a non-identifier name. That, plus JS binding (which allows arbitrary non-identifier names via element access assignment bindings), however, allow such things to be constructed - and as such, we now need to consider a suite of syntax updates we can use to appropriately serialize and represent them in declaration emit. I should have another proposal to at least partially remedy that root issue (in the style of allowing
NS."quoted member name"."another one"
accesses) in the nearish future.