Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Use discriminated unions to "branch" types for Property Names #1345

Closed
Labels
enhancementNew feature or requestpackage: typescript-estreeIssues related to @typescript-eslint/typescript-estree
@bradzacher

Description

@bradzacher

Types for things likeClassProperty/MethodDefinition/Property, etc are pretty ugly.

If the property name is computed, then anyExpression is valid, otherwise onlyIdentifier | Literal is valid.

However we don't represent this in the types, we just have a single object withkey: Expression.

It'll be a bit of extra work, but we can improve upon this by doing something like:

typePropertyNameNonComputed=Identifier|Literal;typePropertyNameComputed=Expression;interfaceClassPropertyBaseextendsBaseNode{type:AST_NODE_TYPES.ClassProperty;key:PropertyNameNonComputed|PropertyNameComputed;computed:boolean;// ... other props}interfaceClassPropertyNonComputedKeyextendsClassPropertyBase{key:PropertyNameNonComputed;computed:false;}interfaceClassPropertyComputedKeyextendsClassPropertyBase{key:PropertyNameComputed;computed:true;}typeClassProperty=ClassPropertyNonComputedKey|ClassPropertyComputedKey;

Nodes we should do this for:

  • ClassProperty
  • TSAbstractClassProperty
  • MethodDefinition
  • TSAbstractMethodDefinition
  • Property
  • TSPropertySignature
  • TSMethodSignature
  • MemberExpression
  • OptionalMemberExpression

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpackage: typescript-estreeIssues related to @typescript-eslint/typescript-estree

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp