Skip to content

Support @const JSDoc tag  #19672

Closed
Closed
@emilio-martinez

Description

@emilio-martinez

TypeScript Version: 2.5.3

Code

/**
 * @const {boolean} This constant is falsy
 */
export const MyFalsyConstant: boolean = false;

Expected behavior:

Type expression and comment should be separate for @const (http://usejsdoc.org/tags-constant.html) tags. See below for further explanation.

Actual behavior:

Parsing the above JSDoc (with help from tsutils which as far as I can see is just using Typescript parsing tools), I get the following node for the @const JSDoc tag.

NodeObject {
  pos: 1299,
  end: 1306,
  flags: 0,
  transformFlags: undefined,
  parent: 
   NodeObject {
     pos: 1292,
     end: 1368,
     flags: 0,
     transformFlags: undefined,
     parent: 
      NodeObject {
        pos: 1290,
        end: 1406,
        flags: 0,
        transformFlags: undefined,
        parent: [Object],
        kind: 208,
        decorators: undefined,
        modifiers: undefined,
        declarationList: [Object],
        jsDoc: [Object],
        _children: [Object] },
     kind: 275,
     tags: [ [Circular], [Object], pos: 1299, end: 1348 ],
     comment: undefined },
  kind: 276,
  atToken: TokenObject { pos: 1299, end: 1300, flags: 0, parent: undefined, kind: 57 },
  tagName: 
   IdentifierObject {
     pos: 1300,
     end: 1305,
     flags: 0,
     parent: undefined,
     escapedText: 'const' },
  comment: '{false} This constant is falsy' }

Destructuring the relevant ts.JSDocTag object (const { typeExpression, comment } = tag), I get the following:

typeExpression: `undefined`
comment: `{false} This constant is falsy`

My expectation would be for the type expression to be separate as outlined in http://usejsdoc.org/tags-constant.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: JSDocRelates to JSDoc parsing and type generationHelp WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions