Skip to content
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

jsdoc @template doesn't work correctly if the comment is before an object property name #17339

Closed
ghost opened this issue Jul 21, 2017 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation Fixed A PR has been merged for this issue

Comments

@ghost
Copy link

ghost commented Jul 21, 2017

TypeScript Version: 2.4.1 and 2.5.0-dev.20170719

Code

// @ts-check

var obj = {
	
	/**
	 * hover: "(property) no_workaround: <T>(a: any[]) => any"  
	 * T in "param" and "returns" say "Cannot find name 'T'."
	 * @template T
	 * @param {T[]} a
	 * @returns {T}
	 */
	no_workaround: function (a) {
		return a[0];
	},
	
	yes_workaround:
	/**
	 * this works correctly: "(property) yes_workaround: <T>(a: T[]) => T"
	 * @template T
	 * @param {T[]} a
	 * @returns {T}
	 */
	function (a) {
		return a[0];
	}
};

// correct return type - "Property 'nonexistent' does not exist on type 'number'."
obj.yes_workaround([1]).nonexistent();

// return type is any so there's no type checking
obj.no_workaround([1]).nonexistent();

Expected behavior:

the type of no_workaround should be the same as yes_workaround (<T>(a: T[]) => T)

Actual behavior:

it's something else: <T>(a: any[]) => any

the type parameter from @template is added to the function's signature but it seems like it's not in scope for the other jsdoc tags (so they show an error and use any), unless the comment block appears right before the function expression like in yes_workaround

@mhegazy mhegazy added the Bug A bug in TypeScript label Aug 23, 2017
@mhegazy mhegazy added Domain: JSDoc Relates to JSDoc parsing and type generation Salsa labels Aug 23, 2017
@mhegazy mhegazy added this to the TypeScript 2.6 milestone Aug 23, 2017
@mhegazy mhegazy modified the milestones: TypeScript 2.7, TypeScript 2.8 Jan 9, 2018
@mhegazy mhegazy modified the milestones: TypeScript 2.8, TypeScript 2.9 Mar 9, 2018
@sandersn
Copy link
Member

sandersn commented May 9, 2018

Fix is up at #23947

@sandersn sandersn added the Fixed A PR has been merged for this issue label May 9, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

2 participants