Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Enhancement(AST): Cleanup TSLiteralType #11587

@bradzacher

Description

@bradzacher

Before You File a Proposal Please Confirm You Have Done The Following...

Relevant Package

ast-spec

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

Currently TSLiteralType is typed to accept Literal | TemplateLiteral | UnaryExpression | UpdateExpression

export interface TSLiteralType extends BaseNode {
type: AST_NODE_TYPES.TSLiteralType;
literal: LiteralExpression | UnaryExpression | UpdateExpression;
}

However this is unnecessarily permissive (playground):

  • You cannot have null literals -- that is instead a TSNullKeyword
  • You cannot have Regex literals -- they are currently a hard TS parser error
  • You cannot have any UnaryExpression -- the only allowable operator is - for negative numbers -- type T = -1 / type U = -1n
  • You cannot have any UpdateExpressions -- ++ and -- are both hard TS parser errors

Proposal:

  • Remove UpdateExpression from the type
  • Refine the Literal union to just the valid literals
  • Refine the UnaryExpression to just the valid operators

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    ASTPRs and Issues about the AST structureaccepting prsGo ahead, send a pull request that resolves this issueenhancementNew feature or requestpackage: ast-specIssues related to @typescript-eslint/ast-specpackage: 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