google / google/closure-compiler

Type casts get stripped by Babel JSX, alternate form needed

Open
#1,782 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

I'm preprocessing my JSX files with Babel, and it's stripping the extraneous comments needed only for Closure Compiler's type cast syntax, resulting in:

```
WARNING - Misplaced type annotation. Type annotations are not allowed here. Are you missing parentheses?
14| */
15| const x = function (a) {
16| let b = /** @type {string} */a;
17| b.indexOf(' ');};
18|
```

It would be good if there was an alternative syntax. Or if the type cast worked like Java's, and took effect on the immediate node following.

Research on whether there's a way to stop Babel doing this has been fruitless. And extending CC to do native JSX transpilation is probably very difficult. Would much appreciate any suggestions other than typing everything "?"!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.