Repository navigation
Computed properties (but not known symbols) - #1752
Conversation
There was a problem hiding this comment.
containing type
Conflicts: src/compiler/checker.ts
There was a problem hiding this comment.
Can you give an example of when this would happen?
There was a problem hiding this comment.
Yes, a good example is tests\cases\conformance\es6\computedProperties\computedPropertyNames32.ts:
function foo<T>() { return '' }
class C<T> {
[foo<T>()]() { }
}I will add this snippet in a comment in the code as well.
There was a problem hiding this comment.
So ensure that either it does not have a computed name OR if it does, it has a symbol? I'm confused.
There was a problem hiding this comment.
OR that it has no name!
There was a problem hiding this comment.
Would it be better to invent a term for this, and put a doc comment above the function that defines the term? I could call it a dynamic name
There was a problem hiding this comment.
We should discuss this; Yui (@yuit) and I think that the "But" is a problem - it's just "And" but it indicates something that is contradictory in intuition.
hasDynamicName is not bad for starters
There was a problem hiding this comment.
Ok, I will change that. You're right, "but" is bad.
Conflicts: tests/baselines/reference/intTypeCheck.errors.txt
Computed properties (but not known symbols)
ES6 allows an arbitrary expression as the name of a property. The syntax is like this:
Here is my current proposal for supporting this feature:
Computed expressions would be allowed in the following places if target is ES6:
Below ES6:
Note that emit for all of the above is straightforward.
Type check:
Questions:
Argument for - we would want this to work:
Argument against - Computed properties would be allowed in class properties, so someone might have a class hierarchy like this: