question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript plugin claims there's unexpected tokens in sane TS

See original GitHub issue

It says there’s an unexpected token here: https://github.com/turt2live/matrix-js-bot-sdk/blob/41eda8a224e2b63ad55659c805df28a9fc8521f5/src/appservice/Appservice.ts#L584

Parsing F:\Workspaces\matrix-misc\matrix-js-bot-sdk\src\appservice\Appservice.ts ...
ERROR: Unable to parse F:\Workspaces\matrix-misc\matrix-js-bot-sdk\src\appservice\Appservice.ts: Unexpected token (584:0)

The other is here: https://github.com/turt2live/matrix-js-bot-sdk/blob/41eda8a224e2b63ad55659c805df28a9fc8521f5/src/appservice/MatrixBridge.ts#L53

Parsing F:\Workspaces\matrix-misc\matrix-js-bot-sdk\src\appservice\MatrixBridge.ts ...
ERROR: Unable to parse F:\Workspaces\matrix-misc\matrix-js-bot-sdk\src\appservice\MatrixBridge.ts: Unexpected token (53:24)

Finally, it explodes with the following when it hits its first interface (https://github.com/turt2live/matrix-js-bot-sdk/blob/41eda8a224e2b63ad55659c805df28a9fc8521f5/src/logging/ILogger.ts):

F:\Workspaces\matrix-misc\matrix-js-bot-sdk\node_modules\better-docs\typescript\type-converter.js:84
  if (type.types && type.types.length) {
           ^

TypeError: Cannot read property 'types' of undefined
    at convertMembers (F:\Workspaces\matrix-misc\matrix-js-bot-sdk\node_modules\better-docs\typescript\type-converter.js:84:12)
    at statement.members.forEach.member (F:\Workspaces\matrix-misc\matrix-js-bot-sdk\node_modules\better-docs\typescript\type-converter.js:164:27)
    at Array.forEach (<anonymous>)
    at ast.statements.map.statement (F:\Workspaces\matrix-misc\matrix-js-bot-sdk\node_modules\better-docs\typescript\type-converter.js:154:27)
    at Array.map (<anonymous>)
    at typeConverter (F:\Workspaces\matrix-misc\matrix-js-bot-sdk\node_modules\better-docs\typescript\type-converter.js:134:25)
    at Parser.beforeParse (F:\Workspaces\matrix-misc\matrix-js-bot-sdk\node_modules\better-docs\typescript.js:27:21)
    at Parser.emit (events.js:189:13)
    at Parser._parseSourceCode (F:\Workspaces\matrix-misc\matrix-js-bot-sdk\node_modules\jsdoc\lib\jsdoc\src\parser.js:288:18)
    at Parser.parse (F:\Workspaces\matrix-misc\matrix-js-bot-sdk\node_modules\jsdoc\lib\jsdoc\src\parser.js:202:22)
    at Object.module.exports.cli.parseFiles (F:\Workspaces\matrix-misc\matrix-js-bot-sdk\node_modules\jsdoc\cli.js:365:46)
    at module.exports.cli.main (F:\Workspaces\matrix-misc\matrix-js-bot-sdk\node_modules\jsdoc\cli.js:234:18)
    at Object.module.exports.cli.runCommand.cb [as runCommand] (F:\Workspaces\matrix-misc\matrix-js-bot-sdk\node_modules\jsdoc\cli.js:186:9)
    at F:\Workspaces\matrix-misc\matrix-js-bot-sdk\node_modules\jsdoc\jsdoc.js:93:9
    at Object.<anonymous> (F:\Workspaces\matrix-misc\matrix-js-bot-sdk\node_modules\jsdoc\jsdoc.js:94:3)
    at Module._compile (internal/modules/cjs/loader.js:689:30)

Tested on both Windows and Ubuntu with the same results. It’s quite possible that I’ve done some human error thing - if that’s the case, please point me in the right direction 😄


jsdoc.json:

{
  "tags": {
    "allowUnknownTags": true
  },
  "plugins": [
    "node_modules/better-docs/category",
    "node_modules/better-docs/typescript"
  ],
  "source": {
    "include": [
      "src"
    ],
    "includePattern": ".ts$"
  },
  "opts": {
    "encoding": "utf8",
    "destination": ".jsdoc",
    "readme": "README.md",
    "recurse": true,
    "verbose": true,
    "template": "node_modules/better-docs"
  }
}

Using command: jsdoc -c jsdoc.json -P package.json

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
wojtek-krysiakcommented, Nov 17, 2019

Ok - there were 3 problems in the examples you mentioned:

  1. arrays defined like this {sth: ‘sth’}[] (fixed in version 1.4.4)
  2. for some reason ts treated this as a React code (fixed in version 1.4.5)
  3. function definition in the interface defined like this: functionName(params) instead of functionnNme: () => any - (fixed in 1.4.6)

PS: here: https://github.com/turt2live/matrix-js-bot-sdk/blob/41eda8a224e2b63ad55659c805df28a9fc8521f5/src/logging/ILogger.ts#L9 you use {*[]} as a type - it is not supported by jsdoc. You can change it to {any[]}

So please download version 1.4.6 and check it out. In case of any more problems - let me know and I will try to fix them.

1reaction
wojtek-krysiakcommented, Nov 16, 2019

no - its probably better-docs error - I will check it out and let you know (probably today)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected token (Note that you need plugins to import files ...
Type imports are erased by typescript, so the compiler never sees it—hence no error is triggered. I suppose common is a .ts file?...
Read more >
TypeScript Deep Dive
code .js file can be renamed to a .ts file and TypeScript will still give you ... JavaScript (and by extension TypeScript) has...
Read more >
SyntaxError: Unexpected token - JavaScript - MDN Web Docs
The JavaScript exceptions "unexpected token" occur when a specific language construct was expected, but something else was provided.
Read more >
babel-jest | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
Error 'unexpected token' with Typescript : r/sveltejs - Reddit
do you get the same? is there a fix? UPDATE: I have installed with npm init vite@latest and then chose options. Now it's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found