bloomberg/ts-blank-space

Support angle bracket type assertion

Closed this issue · 4 comments

Is your feature request related to a problem? Please describe.

Support angle bracket type assertion, e.g.

<ExampleType>exampleValue

Describe the solution you'd like

Strip the cast, e.g.

            exampleValue

Describe alternatives you've considered

Use "as" syntax.

That is not feasible with some codebases that prefer that styles ({"@typescript-eslint/consistent-type-assertions":{assertionStyle:"angle-bracket"}})

Additional context

The documentation incorrectly characterizes angle bracket type assertion as "legacy or discouraged."

except for those TypeScript-specific features that may be considered legacy or discouraged in some way - despite not being formally deprecated.

These unsupported TypeScript features already have preferred alternatives:

Prefix-style type assertions (value) should be replaced with as-style type assertions.

Please correct me if this TypeScript feature is in fact legacy/discouraged (and by whom!).

There's some context as to why this is not supported in the unsupported_syntax docs:

The reason ts-blank-space doesn't support the prefix style is because there are situations where erasing it would change the runtime semantics of the remaining JavaScript.

There are then worked examples, the second of which cannot be accommodated in the same "footprint" as the original source, meaning that source maps would be required for accurate debugging.

In terms of the legacy/discouraged-ness of these kind of type assertions, it's not as clear-cut as some of the other syntaxes which have clearer guidance. Some data points:

  • <> style assertions create ambiguous/awkward parse situations with JSX syntax which uses <> to mean something else
    • as-style assertions were introduced to remedy this in TypeScript 1.6
    • They subsume <> syntax and work in places that it does not
  • The TypeScript documentation chooses to show the majority of Type Assertion examples using as, demonstrating <> only once
  • The TypeScript ESLint rule @typescript-eslint/consistent-type-assertions appears to default to as
  • Prolific TypeScript educator Matt Pocock weighs in in this tweet

Thanks for the explanation.

Thanks for the question! We're not currently planning to support this at the moment, so will close this Issue for now.