Skip to content

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
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

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

2 participants