-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
getJsDocTags
does not return @type
annotations
#13498
Comments
They released TypeScript 2.2 a few days ago, is this still an issue? There is nothing explicitly related to this specific issue on the release notes, but they made some changes related to "tooling when working with editors" as Rossenwasser said, so... maybe? --- EDIT --- I made a few tests and seems that |
Sweet. We have to look into this for YousefED/typescript-json-schema#99. We have to make some changes to work with ts 2.2. |
I think this should work. Can you provide a minimal repro? |
Sure, but for starters, TypeScript 2.1.6 declare namespace ts {
interface Symbol {
getFlags(): SymbolFlags;
getName(): string;
getDeclarations(): Declaration[];
getDocumentationComment(): SymbolDisplayPart[];
getJsDocTags(): JSDocTagInfo[];
}
} TypeScript 2.2.1 declare namespace ts {
interface Symbol {
getFlags(): SymbolFlags;
getName(): string;
getDeclarations(): Declaration[];
getDocumentationComment(): SymbolDisplayPart[];
}
} |
Was this issue closed because it was fixed? |
was miss labeled and auto closed. |
@sandersn can you please reply to this issue with the recommended way to use the new API. |
The API you want is on
/** @TSType int */
let x: number = 12
var ts = require('typescript')
var program = ts.createProgram(['test.ts'], {})
var checker = program.getTypeChecker()
var test_ts = program.getSourceFiles()[1]
var declName = test_ts.statements[0].declarationList.declarations[0].name
var symbol = checker.getSymbolAtLocation(declName)
var type = checker.getTypeAtLocation(declName)
var tags = symbol.getJsDocTags()
console.log(tags) // prints: [ { name: 'TSType', text: 'int ' } ]
console.log(type.intrinsicName) // prints: number |
This area of the code hasn't changed since mid-December, but I can't remember if that was part of 2.1 or 2.2. |
@sandersn Thank you! I can definitely use that. However, I'd love to get type annotations for
/** @TSType int */
let x: number = 12
/** @type int */
let y: number = 12 The code you posted above works but when I try to get the docs for var ts = require('typescript')
var program = ts.createProgram(['test.ts'], {})
var checker = program.getTypeChecker()
var test_ts = program.getSourceFiles()[1]
var declName = test_ts.statements[1].declarationList.declarations[0].name
var symbol = checker.getSymbolAtLocation(declName)
var type = checker.getTypeAtLocation(declName)
var tags = symbol.getJsDocTags()
console.log(tags) // prints: []
console.log(type.intrinsicName) // prints: number What's so special about |
/** @type int */
let y: number = 12 are you missing |
@BANG88 Ups, forgot to copy it. Results are the same. |
The current design is customised closely to what the language service needs. I didn't think about retrieving jsdoc when using typescript as a parser. So Probably getJsDocTags could add a parameter to say whether to retrieve all tags or only custom tags. But either the parser would have to store all tags, or I would need to write code to stuff known tags back into the tag list, since they're parsed into their own, named properties. |
There are internal functions for this but they are not exposed in the d.ts file:
After talking to @weswigham and @rbuckton, we don't see any reason to keep the functions internal. I'll send a PR to make them public. |
I am writing a typescript to JSON schema converter and use the typescript compiler to find out the types and comments of a typescript program. I am using
getJsDocTags
to get annotations and would like to read the@type
annotation.TypeScript Version: 2.1.1
Code
and
For the symbol
integer
, I am callingsymbol.getJsDocTags()
.Expected behavior:
I'd expect to the type jsdoc annotation. In other words, I expect the call to return
[{ name: 'type', text: 'integer' }]
.I understand that
integer
is not a valid js type but this behavior is surprising nonetheless.Actual behavior:
It is missing. I get am empty array
[]
.The text was updated successfully, but these errors were encountered: