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

Support @const JSDoc tag #19672

Closed
emilio-martinez opened this issue Nov 1, 2017 · 8 comments
Closed

Support @const JSDoc tag #19672

emilio-martinez opened this issue Nov 1, 2017 · 8 comments
Labels
Domain: JSDoc Relates to JSDoc parsing and type generation Help Wanted You can do this Suggestion An idea for TypeScript
Milestone

Comments

@emilio-martinez
Copy link

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

@mhegazy mhegazy changed the title @const JSDoc tag doesn't separate typeExpression from comment Support @const JSDoc tag Nov 1, 2017
@mhegazy mhegazy added Domain: JSDoc Relates to JSDoc parsing and type generation Suggestion An idea for TypeScript labels Nov 1, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Nov 1, 2017

PRs welcomed.

@j-oliveras
Copy link
Contributor

@mhegazy Maybe you want to add help wanted label to this issue (based on your previous comment).

@mhegazy mhegazy added the Help Wanted You can do this label Mar 28, 2018
@mhegazy mhegazy added this to the Community milestone Mar 28, 2018
@RyanCavanaugh RyanCavanaugh modified the milestones: Community, Backlog Mar 7, 2019
@Kingwl
Copy link
Contributor

Kingwl commented Jul 27, 2020

I’d like to work on this.

@zachhardesty7
Copy link

has any progress been made on this issue? from what I can tell, it looks like #39768 was finished but closed.

@frank-dspeed
Copy link

frank-dspeed commented Apr 14, 2022

This can be closed Typescript now Supports: since version 4.5+ #39768 implements it

export const CBLErrorDomainByCode = /** @type {const} */ ([, "LITE_CORE","POSIX","SQLITE","FLEECE","NETWORK","WEB_SOCKET"]);

is type

const CBLErrorDomainByCode: readonly [undefined, "LITE_CORE", "POSIX", "SQLITE", "FLEECE", "NETWORK", "WEB_SOCKET"]

works like a charm @RyanCavanaugh

https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#unsupported-tags <- needs a update i do not remember where the issues are for this.

@bjarkler
Copy link

I don't think this is fixed - can we reopen, @RyanCavanaugh? #39768 was closed without being merged, and the example in the previous comment uses the @type tag, not the @const tag which this issue is referring to.

@frank-dspeed
Copy link

frank-dspeed commented Apr 26, 2022

@bjarkler i guess there is no real implementation ongoing with the @const JSDoc tag what now works is the so called typecasting to const so the same as in typescript with as const

i guess thats because it needs to get done and made sure that it is only on assignment.

@GreenAsJade
Copy link

Note that the documentation for Typescript points to this issue as being open on this tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: JSDoc Relates to JSDoc parsing and type generation Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants