Skip to content

In JS, type parameter from @type JSDoc tag doesn't get instantiated #25618

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

Closed
ajafff opened this issue Jul 12, 2018 · 0 comments · Fixed by #26694
Closed

In JS, type parameter from @type JSDoc tag doesn't get instantiated #25618

ajafff opened this issue Jul 12, 2018 · 0 comments · Fixed by #26694
Assignees
Labels
Bug A bug in TypeScript checkJs Relates to checking JavaScript using TypeScript Fixed A PR has been merged for this issue

Comments

@ajafff
Copy link
Contributor

ajafff commented Jul 12, 2018

TypeScript Version: 3.0.0-dev.20180712

Search Terms:

Code

// @checkJs: true
// @allowJs: true

// @filename: test.js

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

Expected behavior:

Either param doesn't get it's type from the @type tag or the type parameter T applies to the function.

Actual behavior:

Argument of type '1' is not assignable to parameter of type 'T | undefined'.

Playground Link: not possible

Related Issues: #25525

@mhegazy mhegazy added this to the TypeScript 3.1 milestone Jul 12, 2018
@mhegazy mhegazy added Bug A bug in TypeScript Salsa checkJs Relates to checking JavaScript using TypeScript labels Jul 12, 2018
@sandersn sandersn changed the title In JS, function declaration should use type parameter of @type JSDoc tag In JS, type parameter of @type JSDoc tag doesn't get instantiated Jul 12, 2018
@sandersn sandersn changed the title In JS, type parameter of @type JSDoc tag doesn't get instantiated In JS, type parameter from @type JSDoc tag doesn't get instantiated Jul 12, 2018
@sandersn sandersn added the Fixed A PR has been merged for this issue label Aug 27, 2018
sandersn added a commit that referenced this issue Aug 27, 2018
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 added a commit that referenced this issue Aug 27, 2018
* Get [type] parameter types from @type tag

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

* Fix split ifs according to PR comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript checkJs Relates to checking JavaScript using TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants