Skip to content

AsExpression precedence hazard #62

Description

@qnighy

Describe the bug

as and satisfies have a strange precedence rule that implicitly introduces operator regrouping. Simply erasing the operator may result in wrong grouping.

To Reproduce

Transpilers print 1 for the following code, while type erasers print 1.5.

console.log(1 + 1 as number / 2);

Expected behavior

As there is no guaranteed room for (, type erasers should reject this kind of AsExpressions and SatisfiesExpressions.

Environment (please complete the following information):

  • Operating System and Version: confirmed on Windows 11

Additional context

I found this while writing up an unofficial spec documentation and the example above is merely synthetic. I am raising an issue here first because ts-blank-space seems rather strict about such hazards. I will ask other tool authors about the same hazard.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions