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

JSDoc type reference doesn't skip leading asterisk #32280

Open
golopot opened this issue Jul 7, 2019 · 4 comments
Open

JSDoc type reference doesn't skip leading asterisk #32280

golopot opened this issue Jul 7, 2019 · 4 comments
Labels
Bug A bug in TypeScript
Milestone

Comments

@golopot
Copy link

golopot commented Jul 7, 2019

TypeScript Version: typescript@3.6.0-dev.20190704

Search Terms:
checkjs
jsdoc
multi-line
multiline
Code

/**
 * @returns {
 *   | 'a'
 *   | 'b'
 *   | 'c'
 * } - this type is parsed as `any`.
 */
function f() {
  return true;
}

Expected behavior:
Error on incompatible return type.
Actual behavior:
No error. The jsdoc return type is parsed as any.
Playground Link:
Not available.

@orta
Copy link
Contributor

orta commented Jul 8, 2019

This isn't a real type in TypeScript terms - are you trying to describe something which returns 'a' or 'b' or 'c'?

If so, you probably want:

/**
 * @returns  'a' | 'b' | 'c
 */
function f() {
  return true;
}

playground

The { and } are used for interfaces, a union doesn't need them

@orta orta closed this as completed Jul 8, 2019
@golopot
Copy link
Author

golopot commented Jul 8, 2019

@orta
That is not true. The { and } are JSDoc's syntax, used as delimiter for type expressions. ref. A valid jsdoc comment looks like this: /** @param {string} - some descriptions. */.

@golopot
Copy link
Author

golopot commented Jul 8, 2019

cc @sandersn

@sandersn sandersn reopened this Jul 8, 2019
@sandersn sandersn changed the title CheckJS bug on some multi-line jsdoc type Leading asterisk not skipped inside JSDoc type Jul 8, 2019
@sandersn
Copy link
Member

sandersn commented Jul 8, 2019

Yep, this is a real bug! The prefix-pipe syntax obscures it a bit. Here's a simpler repro:

/**
 * @returns {
 *  'a'}
 */
function f() {
  return true;
}

Note that subsequent asterisks are fine, it's just leading asterisk before the type gets started:

/**
 * @returns {
   'a'
 * | 'b' }
 */
function f() {
  return true;
}

That's because type parsing uses Typescript rules, which have a hacky exemption for asterisks inside jsdoc. But it's clearly not reliable. I'm pretty sure it's because all the tests we added are for object types, which we expected to be formatted like this:

/**
 * @returns {{
 *   a: number
 * }}
 */

Here, the type starts before the newline-asterisk sequence.

@sandersn sandersn added the Bug A bug in TypeScript label Jul 8, 2019
@sandersn sandersn added this to the Backlog milestone Jul 8, 2019
@sandersn sandersn changed the title Leading asterisk not skipped inside JSDoc type JSDoc type reference doesn't skip leading asterisk Jul 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants