Skip to content

Javascript error which isn't one: 'type arguments' can only be used in a .ts file #29235

Description

@masbaehr
  • VSCode Version: 1.31-insider
  • OS Version: Windows 10 Pro

image

Activity

  1. octref commented on Dec 30, 2018

    @octref

    Please include reproducible steps.

  2. masbaehr commented on Dec 31, 2018

    @masbaehr
    Author

    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.

  3. removed their assignment
    on Jan 2, 2019
  4. mjbvz commented on Jan 2, 2019

    @mjbvz

    confirmed using typescript@3.3.0-dev.20190101

    The pattern that causes issues is:

    if((0)<0>(0)){ }
    
  5. fatcerberus commented on Jan 2, 2019

    @fatcerberus

    Hmm, it appears to think the stuff inside <> is a type argument, in this case it’s <(n|0)|(e|0)> which I guess the compiler thinks is a type union...

    My instinct is that the error message should probably be removed entirely and the compiler just treat it as a normal < or > operator when inside a .js file.

  6. DanielRosenwasser commented on Jan 2, 2019

    @DanielRosenwasser
    Member

    Basic idea is that when the file is a JS/JSX file, don't try to parse type arguments for

    • call expressions
    • new expressions
    • tagged template strings
    • JSX
    • decorators (I don't even think we currently do at all)
  7. 9 remaining items

  8. fatcerberus commented on Jan 4, 2019

    @fatcerberus

    What I was getting at was there's no guarantee that a minifier won't produce code that looks exactly like x<y>(z). Even in the code sample in the OP you can see it comes dangerously close to doing so--the parentheses are only present because it does x|0 which binds more loosely than greater than/less than. Variables in general aren't parenthesized.

  9. fatcerberus commented on Jan 4, 2019

    @fatcerberus

    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 .js file; I'm just not sure if that's practical.

  10. Kingwl commented on Jan 4, 2019

    @Kingwl
    Contributor

    I have a (work in progress) tried on my branch Kingwl@9143748 but I'm not sure that is expected

  11. Dalzhim commented on Jul 9, 2020

    @Dalzhim

    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 // @ts-ignore both before the import and before the line where the error is reported. I have tried using the // @ts-nocheck comment at the beginning of the generated file. There doesn't seem to be any way to silence this false positive.

  12. DanielRosenwasser commented on Jul 9, 2020

    @DanielRosenwasser
    Member

    I think this is fixed by #36673, right?

  13. Dalzhim commented on Jul 10, 2020

    @Dalzhim

    I am not sure whether or not I did the test correctly. I have modified my package.json file entry to : "typescript": "mprobst/TypeScript#f308ac136d420a71819616207a0358b8d369a9cc" and ran npm install afterwards. After doing that, the error remains when I compile my project.

    TS8011: Type arguments can only be used in TypeScript files.
    TS1139: Type parameter declaration expected.
    

    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.

  14. Dalzhim commented on Jul 10, 2020

    @Dalzhim

    I have successfully cloned mprobst/TypeScript:parse-js and built the package. It now fails with the following error :

    ERROR in ./src/client/app/index.js
    Module build failed (from ./node_modules/ts-loader/index.js):
    Error: Debug Failure. Unexpected node.
    Node ComputedPropertyName was unexpected.
        at bindThisPropertyAssignment (/TypeScript/lib/typescript.js:32648:30)
        at bindWorker (/TypeScript/lib/typescript.js:32280:29)
        at bind (/TypeScript/lib/typescript.js:32160:13)
        at visitNode (/TypeScript/lib/typescript.js:18468:24)
        at Object.forEachChild (/TypeScript/lib/typescript.js:18884:21)
        at bindEachChild (/TypeScript/lib/typescript.js:30688:16)
        at bindChildrenWorker (/TypeScript/lib/typescript.js:30783:21)
        at bindChildren (/TypeScript/lib/typescript.js:30658:17)
        at bind (/TypeScript/lib/typescript.js:32171:21)
        at bindEach (/TypeScript/lib/typescript.js:30680:21)
        at visitNodes (/TypeScript/lib/typescript.js:18473:24)
        at Object.forEachChild (/TypeScript/lib/typescript.js:18864:21)
        at bindEachChild (/TypeScript/lib/typescript.js:30688:16)
        at bindChildrenWorker (/TypeScript/lib/typescript.js:30783:21)
        at bindChildren (/TypeScript/lib/typescript.js:30658:17)
        at bind (/TypeScript/lib/typescript.js:32171:21)
        at visitNode (/TypeScript/lib/typescript.js:18468:24)
        at Object.forEachChild (/TypeScript/lib/typescript.js:18850:24)
        at bindEachChild (/TypeScript/lib/typescript.js:30688:16)
        at bindChildrenWorker (/TypeScript/lib/typescript.js:30783:21)
        at bindChildren (/TypeScript/lib/typescript.js:30658:17)
        at bind (/TypeScript/lib/typescript.js:32171:21)
        at visitNode (/TypeScript/lib/typescript.js:18468:24)
        at Object.forEachChild (/TypeScript/lib/typescript.js:18538:21)
        at bindEachChild (/TypeScript/lib/typescript.js:30688:16)
        at bindChildrenWorker (/TypeScript/lib/typescript.js:30783:21)
        at bindChildren (/TypeScript/lib/typescript.js:30658:17)
        at bind (/TypeScript/lib/typescript.js:32171:21)
        at bindEach (/TypeScript/lib/typescript.js:30680:21)
        at visitNodes (/TypeScript/lib/typescript.js:18473:24)
        at Object.forEachChild (/TypeScript/lib/typescript.js:18783:21)
        at bindEachChild (/TypeScript/lib/typescript.js:30688:16)
        at bindChildrenWorker (/TypeScript/lib/typescript.js:30783:21)
        at bindChildren (/TypeScript/lib/typescript.js:30658:17)
        at bindContainer (/TypeScript/lib/typescript.js:30639:17)
        at bind (/TypeScript/lib/typescript.js:32174:21)
        at /TypeScript/lib/typescript.js:30664:94
        at bindEach (/TypeScript/lib/typescript.js:30680:21)
        at bindEachFunctionsFirst (/TypeScript/lib/typescript.js:30664:13)
        at bindChildrenWorker (/TypeScript/lib/typescript.js:30774:21)
        at bindChildren (/TypeScript/lib/typescript.js:30658:17)
        at bindContainer (/TypeScript/lib/typescript.js:30604:17)
     @ multi @babel/polyfill ./src/index.js bundle[1]
    

    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 upstream/master into my local copy of mprobst/TypeScript:js-parse and I still get the above error. Therefore, I am unable at this moment to confirm without any doubts that the error is resolved. I will wait for feedback before doing any further testing on this PR.

  15. jakebailey commented on Jul 14, 2023

    @jakebailey
    Member

    This is an old issue, but this was definitely fixed by #36673 in TS 4.2.

  16. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: JavaScriptThe issue relates to JavaScript specificallyEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do this

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions