bloomberg / ts-blank-space

A small, fast, pure JavaScript type-stripper that uses the official TypeScript parser.
https://bloomberg.github.io/ts-blank-space
Apache License 2.0
544 stars 8 forks source link

Support angle bracket type assertion #12

Closed pauldraper closed 1 month ago

pauldraper commented 1 month ago

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!).

tchetwin commented 1 month ago

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.

tchetwin commented 1 month ago

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:

pauldraper commented 1 month ago

Thanks for the explanation.

tchetwin commented 1 month ago

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