Skip to content
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

Fails to parse TS types that TS parses #1898

Open
wmertens opened this issue Mar 25, 2021 · 4 comments
Open

Fails to parse TS types that TS parses #1898

wmertens opened this issue Mar 25, 2021 · 4 comments

Comments

@wmertens
Copy link

Input code

VSCode IntelliSense is happy with these definitions in a JS file:

/**
 * @type {{quoteId: quoteSqlId} & SqlTag}
 * @typedef {(
 * 	tpl: string[],
 * 	...interpolations: string[]
 * ) => [string, string[]]} SqlTag
 */
export const sql = (tpl, ...interpolations) => {return ['foo', ['bar']]}

JSDoc debug output

...but JSDoc isn't:

DEBUG: JSDoc 3.6.6 (Sun, 20 Sep 2020 02:25:14 GMT)
DEBUG: Environment info: {"env":{"conf":{"plugins":[],"recurseDepth":10,"source":{"includePattern":".+\\.js(doc|x)?$","excludePattern":"(^|\\/|\\\\)_"},"sourceType":"module","tags":{"allowUnknownTags":true,"dictionaries":["jsdoc","closure"]},"templates":{"monospaceLinks":false,"cleverLinks":false,"default":{"outputSourceFiles":true}}},"opts":{"_":["t.js"],"explain":true,"debug":true,"destination":"./out/","encoding":"utf8"}}}
DEBUG: Parsing source files: ["/home/wmertens/Projects/strato-db/t.js"]
Parsing /home/wmertens/Projects/strato-db/t.js ...
ERROR: Unable to parse a tag's type expression for source file /home/wmertens/Projects/strato-db/t.js in line 1 with tag title "type" and text "{{quoteId: quoteSqlId} & SqlTag}": Invalid type expression "{quoteId: quoteSqlId} & SqlTag": Expected "|" but "&" found.
ERROR: Unable to parse a tag's type expression for source file /home/wmertens/Projects/strato-db/t.js in line 1 with tag title "typedef" and text "{(
        tpl: string[],
        ...interpolations: string[]
) => [string, string[]]} SqlTag": Invalid type expression "(
        tpl: string[],
        ...interpolations: string[]
) => [string, string[]]": Expected "$", "'", ".", "0", "@", "\"", "\\", "_", "break", "case", "catch", "class", "const", "continue", "debugger", "default", "delete", "do", "else", "enum", "export", "extends", "finally", "for", "function", "if", "implements", "import", "in", "instanceof", "interface", "let", "new", "package", "private", "protected", "public", "return", "static", "super", "switch", "this", "throw", "try", "typeof", "var", "void", "while", "with", "yield", Unicode letter number, Unicode lowercase letter, Unicode modifier letter, Unicode other letter, Unicode titlecase letter, Unicode uppercase letter, or [1-9] but " " found.
ERROR: Unable to parse a tag's type expression for source file /home/wmertens/Projects/strato-db/t.js in line 8 with tag title "type" and text "{{quoteId: quoteSqlId} & SqlTag}": Invalid type expression "{quoteId: quoteSqlId} & SqlTag": Expected "|" but "&" found.
ERROR: Unable to parse a tag's type expression for source file /home/wmertens/Projects/strato-db/t.js in line 8 with tag title "typedef" and text "{(
        tpl: string[],
        ...interpolations: string[]
) => [string, string[]]} SqlTag": Invalid type expression "(
        tpl: string[],
        ...interpolations: string[]
) => [string, string[]]": Expected "$", "'", ".", "0", "@", "\"", "\\", "_", "break", "case", "catch", "class", "const", "continue", "debugger", "default", "delete", "do", "else", "enum", "export", "extends", "finally", "for", "function", "if", "implements", "import", "in", "instanceof", "interface", "let", "new", "package", "private", "protected", "public", "return", "static", "super", "switch", "this", "throw", "try", "typeof", "var", "void", "while", "with", "yield", Unicode letter number, Unicode lowercase letter, Unicode modifier letter, Unicode other letter, Unicode titlecase letter, Unicode uppercase letter, or [1-9] but " " found.
DEBUG: Finished parsing source files.
DEBUG: Adding inherited symbols, mixins, and interface implementations...
DEBUG: Adding borrowed doclets...
DEBUG: Post-processing complete.

Expected behavior

It should not error but at most warn, and just assume that the whole thing is a valid type

Current behavior

  • A & B is not supported
  • (a: string[], ...b: string[]) => c is not supported

Your environment

Software Version
JSDoc 3.6.6
Node.js 12
npm 6
Operating system NixOS
@Zargith
Copy link

Zargith commented Mar 29, 2021

I got a similar error and I just solved it: #1897 (comment)
Hope it can helps you !

@wmertens
Copy link
Author

@Zargith thanks, but you're simply ignoring those files, right? I do want to use these types for documentation.

@Zargith
Copy link

Zargith commented Mar 29, 2021

@wmertens told that because I mostly had the same error message but don't know if it could helps you 😅

@simonseyock
Copy link

Hey, sadly JsDoc does not support TypeScript types at the moment. The parser does not support it. See #1917

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants