Closed
Description
Types for things like ClassProperty
/MethodDefinition
/Property
, etc are pretty ugly.
If the property name is computed, then any Expression
is valid, otherwise only Identifier | Literal
is valid.
However we don't represent this in the types, we just have a single object with key: Expression
.
It'll be a bit of extra work, but we can improve upon this by doing something like:
type PropertyNameNonComputed = Identifier | Literal;
type PropertyNameComputed = Expression;
interface ClassPropertyBase extends BaseNode {
type: AST_NODE_TYPES.ClassProperty;
key: PropertyNameNonComputed | PropertyNameComputed;
computed: boolean;
// ... other props
}
interface ClassPropertyNonComputedKey extends ClassPropertyBase {
key: PropertyNameNonComputed;
computed: false;
}
interface ClassPropertyComputedKey extends ClassPropertyBase {
key: PropertyNameComputed;
computed: true;
}
type ClassProperty = ClassPropertyNonComputedKey | ClassPropertyComputedKey;
Nodes we should do this for:
ClassProperty
TSAbstractClassProperty
MethodDefinition
TSAbstractMethodDefinition
Property
TSPropertySignature
TSMethodSignature
MemberExpression
OptionalMemberExpression