Skip to content

Support @typedef as member of namespace #25579

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

Open
ghost opened this issue Jul 11, 2018 · 7 comments
Open

Support @typedef as member of namespace #25579

ghost opened this issue Jul 11, 2018 · 7 comments
Labels
checkJs Relates to checking JavaScript using TypeScript Domain: JavaScript The issue relates to JavaScript specifically Domain: JSDoc Relates to JSDoc parsing and type generation In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@ghost
Copy link

ghost commented Jul 11, 2018

TypeScript Version: 3.0.0-dev.20180711

Code

class C {
    /** @typedef {number} N */

    /** @type {N} */
    x = 0; // works
}

/**
 * @memberof C
 * @typedef {number} M
 */

/** @type {C.N} */
const x = 0; // broke

/** @type {C.M} */
const y = 0; // broke

Expected behavior:

No error.

Actual behavior:

C.N and C.M don't exist.

@ghost ghost added Suggestion An idea for TypeScript Salsa Domain: JSDoc Relates to JSDoc parsing and type generation checkJs Relates to checking JavaScript using TypeScript labels Jul 11, 2018
@bennidi
Copy link

bennidi commented Jul 12, 2018

@Andy-MS Thanks for moving my report here. I am currently seeing the behavior that also the part that you claim works, doesn't work. In my report I stated that I tried different reference/namespace patterns. Leaving out any namespace was one of them. I never got intellisense to show me the correct return type when using @typedef. The following doesnt work for me in VSCODE intellisense

/**
 * @typedef {object} CancelReservationResult
 * @property {number} updated 1 if the vehicle was updated, zero otherwise
 * @property {boolean} [vehicle] - The updated vehicle
 * @property {boolean} [reservation] - The former reservation of the updated vehicle
 */
//some code in between
  /**
   * @summary Remove a reservation from a vehicle if that reservation is owned by the given user
   *
   * @param {Object} params
   * @param {Number} vehicleId The vehicle that will have its reservation removed
   * @param {Number} userId The user holding the reservation
   * @returns {CancelReservationResult}
   */
  // service method declaration...

@bennidi
Copy link

bennidi commented Jul 16, 2018

I followed instructions to update to the latest typescript version ([email protected]
) and it still doesnt work for me.

@ghost
Copy link
Author

ghost commented Jul 16, 2018

@bennidi Could you post a complete example? Just that code works for me:
worksforme

@bennidi
Copy link

bennidi commented Jul 25, 2018

Thanks for checking it out. I think I was not precise enough about what works and what doesn't work. What I expect intellisense to do is to show me details about the return type, when I hover over the function. I do receive the same results as you get, when I type fnc().up - although I don't know why fnc(). is by default scrolled to the end of the suggestion list, so I don't see the most meaningful results first.

data

Maybe this is a VSCODE config thing. Also the variable shows the correct type declaration.

I am missing something else, so maybe I am reporting a feature request and you can redirect me instead. Here is what I see with the @typedef as return type

screenshot_20180725_155957

It is correct information but I don't see what this type looks like at all. While not giving any type info I receive

screenshot_20180725_160306

I find this much more useful than just seeing the name of the type. If you think that this could be a relevant feature request for VSCODE, how should I proceed? And thanks for your support and sorry for not being so precise/clear enough in the beginning.

@ghost
Copy link
Author

ghost commented Jul 25, 2018

I think that's working as intended, since we prefer to show the name of a type instead of the contents of a type. (Imagine if the return type had a property that contained another type, would we expand that too?)
One way to see more info about the type is to not look at f, but at result -- right click and choose "Go to Type Definition" (see also #25933).

Also, completions are different depending on whether you have checkJs enabled. If you do, you'll get only completions that would be type appropriate. So at f()., you'll only see updated, vehicle, and reservation. But if checkJs is turned off, you'll get a completion for every identifier in the file, including names of functions and types that are obviously wrong. Maybe we should put some effort into improving that (#25931).

@weswigham weswigham added the In Discussion Not yet reached consensus label Nov 6, 2018
@weswigham weswigham added Domain: JavaScript The issue relates to JavaScript specifically and removed Domain: JavaScript The issue relates to JavaScript specifically Salsa labels Nov 29, 2018
@brendanarnold
Copy link

For what it's worth I still get the original issue, basically TypeScript does not recognise the @memberof attribute. I know it is not supported but I am working on a codebase that heavily uses it and the 'checkJs' leaves red squigglies everywhere. I definitely second it being implemented.

@thw0rted
Copy link

I just realized this doesn't have a trackback to #28730. The fact that it's in a namespace is a special case but I think general support for the memberof tag falls under that issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
checkJs Relates to checking JavaScript using TypeScript Domain: JavaScript The issue relates to JavaScript specifically Domain: JSDoc Relates to JSDoc parsing and type generation In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

5 participants