Skip to content

Get [type] parameter types from @type tag #26694

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

Merged
merged 2 commits into from
Aug 27, 2018

Conversation

sandersn
Copy link
Member

Previously only the return type was used in cases like this:

/** @type {<T>(param?: T) => T | undefined} */
function g(param) {
  return param;
}

Now the type parameters from the type tag are used, and the compiler gets the type of the parameter by using the position in the signature of the type tag.

Note that this isn't the most complete fix — it only works for function types written directly in the type tag, not type references. However, I don't think that's very common, so I'd prefer to wait until I have evidence that it is. (I believe that supporting arbitrary references would require quite a bit more code.)

Fixes #25618

Previously only the return type was used in cases like this:

```js
/** @type {<T>(param?: T) => T | undefined} */
function g(param) {
  return param;
}
```

Now the type parameters from the type tag are used, and the compiler
gets the type of the parameter by using the position in the signature of
the type tag.

Fixes #25618
@sandersn sandersn requested review from a user and RyanCavanaugh August 27, 2018 20:21
}
const typeTag = getJSDocType(node);
if (typeTag) {
if (isFunctionTypeNode(typeTag) && typeTag.typeParameters) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the nested if?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason! Fixed.

@sandersn sandersn merged commit a2e4a28 into master Aug 27, 2018
@sandersn sandersn deleted the jsdoc/get-param-type-from-type-tag branch August 27, 2018 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

In JS, type parameter from @type JSDoc tag doesn't get instantiated
1 participant