-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Javascript error which isn't one: 'type arguments' can only be used in a .ts file #29235
Comments
Please include reproducible steps. |
Just put this file into the editor and open it: https://github.com/schmich/instascan/releases/download/1.0.0/instascan.min.js Usually other minified js files open normally and syntax highlighting still works, but not this one. I can't exclude this is an error in the file but even then the error message is probably wrong. |
confirmed using [email protected] The pattern that causes issues is:
|
Hmm, it appears to think the stuff inside My instinct is that the error message should probably be removed entirely and the compiler just treat it as a normal |
Basic idea is that when the file is a JS/JSX file, don't try to parse type arguments for
|
@DanielRosenwasser I don't think not parsing type arguments is correct fix. We do that so we can report better errors.
|
It's a type error in TypeScript, but it would've parsed as different but syntactically valid JavaScript. In this case, that code is generated my another program, so saying "that's not valid JS" is weird. |
No, like, the issue moreso that we shouldn't be interpreting that pattern as type arguments in any language variant, ideally. |
I don't think that's possible in the general case; what if instead the pattern is |
We could trim back the scope of what we parse as type arguments, however - while |
For anyone interested and reading this issue, |
What I was getting at was there's no guarantee that a minifier won't produce code that looks exactly like |
That being said, I agree it would be nice to keep the error for the benefit of people trying to write TS code in a |
I have a (work in progress) tried on my branch Kingwl@9143748 but I'm not sure that is expected |
I have the same kind of problem and I've been searching for hours for a workaround that I could use without any success. I am using Emscripten to compile some C++ code into JavaScript. It produces a JavaScript file. I have to import the generated *.js file from within a *.tsx file in order to leverage the exposed functions. I have tried using the |
I think this is fixed by #36673, right? |
I am not sure whether or not I did the test correctly. I have modified my
Edit: I'm now quite certain my test is not correct as I can look into node_modules/typescript/lib/tsc.js and I see the old version of the code prior to the commit. |
I have successfully cloned
Edit 1 : I have tried using the revision prior to the merge request : 2cc5856, and the above error was already present before the commit in the pull request. Edit 2 : I have merged |
This is an old issue, but this was definitely fixed by #36673 in TS 4.2. |
The text was updated successfully, but these errors were encountered: