Christopher King
Christopher King

Reputation: 1062

Does the Typescript compiler expose the default value of JsDoc @param?

I expected to be able to extract the default value of a JsDoc param but I'm actually unable to find the default value on the JsDoc node. For example, give this:

/** * @param [foo=42] This is foo! */

I'd like to extract '42' from the node. Yet I find no default value field on the ts node:

enter image description here

It exposes isBracketed but I cannot find the 42. Typescript does claim to support default JsDoc arguments:

https://github.com/Microsoft/TypeScript/wiki/JSDoc-support-in-JavaScript#param-and-returns

Yet I cannot seem to find the exposed in the AST... :<

Before I log a bug, I figured I'd ask around and see if anyone knows the secret handshake.

Upvotes: 3

Views: 500

Answers (1)

David Sherret
David Sherret

Reputation: 106840

No, it's not currently in the AST. The parser currently skips over the expression without storing the return value anywhere.

// May have an optional default, e.g. '[foo = 42]'
if (parseOptionalToken(SyntaxKind.EqualsToken)) {
    parseExpression();
}

Source

Upvotes: 2

Related Questions