Skip to content

JSDoc template interference #16485

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
dyst5422 opened this issue Jun 13, 2017 · 3 comments
Closed

JSDoc template interference #16485

dyst5422 opened this issue Jun 13, 2017 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@dyst5422
Copy link

TypeScript Version: 2.4

Code
Example 0
ERROR: error TS2536: Type '"prop"' cannot be used to index type 'T'.
ERROR: error TS2339: Property 'prop' does not exist on type 'T'.

/**
 * Example 0
 * @class GenericClass
 * @template T
 */
class GenericClass<T extends { prop: string }> { // Doesn't work
  public insert(arg: T): T['prop'] {
    return arg.prop;
  }
}

Example 1
Works fine

/**
 * Example 1
 * @class OtherGenericClass
 */
class OtherGenericClass<T extends { prop: string }> { // Works
  public insert(arg: T): T['prop'] {
    return arg.prop;
  }
}

Example 2
ERROR: error TS2536: Type '"prop"' cannot be used to index type 'T'.
ERROR: error TS2339: Property 'prop' does not exist on type 'T'.

/**
 * Example 2
 * @template T
 * @param {T} arg
 * @returns {T['prop']}
 */
function myFunc<T extends { prop: string }> (arg: T): T['prop'] { // Doesn't work
  return arg.prop;
}

Example 3
Works fine

/**
 * Example 3
 * @param {R} arg
 * @returns {R['prop']}
 */
function myOtherFunc<R extends { prop: string }> (arg: R): R['prop'] { // Works
  return arg.prop;
}

Expected behavior:
Template declaration in JSDoc comments should not supersede the in-code template declarations.

Actual behavior:
In example 0 and 2 above, the generic type T is not found to properly extend { prop: string } when the JSDoc comment exists presumably because the JSDoc comment supersedes the type defined inline. This should never be the case where a non-code element takes precedence over the code contents.

@dyst5422
Copy link
Author

#16411 is related

@ghost
Copy link

ghost commented Jun 13, 2017

Duplicate of #16358. Fixed in typescript@next.

@ghost ghost added the Duplicate An existing issue was already created label Jun 13, 2017
@dyst5422
Copy link
Author

Ah good. I looked around for a bit, but hadn't seen that one. I'll close this duplicate issue.

@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

1 participant