-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[Salsa] Support jsdoc @namespace
#14233
Comments
Is there any workaround for this? I want to use my object at the type level. I tried using {
class Foo {}
const X = { Foo }
// line below errors with "Cannot find name 'typeof'"
/** @type {typeof X.Foo} */
const foo = new X.Foo()
} |
would be subsumed by a fix for #16489 |
@mhegazy // @filename: interfaces.d.ts
export interface Foo {}
// @filename: usage.js
/** @namespace {import('./interfaces')} NS */
/** @type {NS.Foo} */
let foo; Seems that |
you can just use: // @filename: usage.js
/** @typedef {import('./interfaces').Foo} Foo */
/** @type {Foo} */
let foo; |
@mhegazy
What can I do with this? |
This is really just expanding on @que-etc's comment: Currently there doesn't seem to be a way to alias namespaces in JSDoc like you can do with a TS I can use /** @typedef {lib.data.persistence.MyType} MyType */ But I can't do the same with a namespace because it's not a type: /** @typedef {lib.data.persistence} types */
Namespace 'global.lib.data' has no exported member 'persistence'. ts(2694) Or if it does happen to be a type too, its namespace meaning isn't recognized in subsequent paths: /** @type {types.MyType} */
let someVar;
'types' only refers to a type, but is being used as a namespace here. ts(2702) If I have a whole bunch of types from that namespace that I want to use, I have to qualify them with the whole path every time, or go through and alias them one by one. It's the same issue with I would very much like to be able to do: /** @namespace {lib.data.persistence} types */
/** @namespace {import('../../../lib/data').persistence} types */ or something along those lines. Maybe using the |
My project is a vanilla Javascript project and we use JSDocs for documentation and to enable some degree of type checking in VSCode and for JSDoc code generation. Webstorm supports the standard This is very annoying for the project team, half of which use VSCode and half use WebStorm. |
Dealing with JSDoc Which is weird, and I guess that is how JSDoc handles these types? ...but it is still strange you cannot simply reference a generic type in a Taking advantage of JSDoc's virtual namespaces could alleviate this problem, allowing you to specify your aliases as a member of a virtual namespace, then import the namespace, reference the generic type, and provide the type parameters when and where you need them. Funny enough, TypeScript does support virtual namespaces within the same file by simply creating a // File: ./types.js
/**
* @template T
* @typedef {T | Promise.<T>} Aliases.MaybePromise
*/
// This checks correctly...
/** @typedef {Aliases.MaybePromise.<string>} MaybePromisedString */ However, TypeScript does not export these top-level virtual namespaces as it does with other // File: ./elsewhere.js
// This fails with a "...has no exported member 'Aliases'" error.
/** @typedef {import("./types").Aliases} Aliases */
// Naturally, since the import failed, this fails to check.
/** @typedef {Aliases.MaybePromise.<string>} MaybePromisedString */ I think supporting, at a minimum, a One potential idea to consider is to utilize JSDoc namepaths and treat a module referenced with the But implementing this would be a breaking change in JSDoc support. Right now, the Using namepaths to disambiguate between the two cases seems more like the JSDoc way, but the |
SO, what's the news? |
The problem persists
My code
Any update guys? |
Just here to say that I expected the following to work in a Javascript file and it didn't work:
as a not very obvious workaround, I used
instead. It would be good if the first version using |
This seems like an absolute no-brainer. Without it, I have to typdef-alias each individual type I want to use at the top of the file like /** @typedef {import("@googlemaps/google-maps-services-js").DistanceMatrixRequest} DistanceMatrixRequest */ This both looks very messy, is overly verbose (I have to repeat the module names so many times) and forces me to disable my comment-length reflow ESLint plugin! |
Support treating variable declarations with
@namespace
JSDoc tag as TS namespaces.The text was updated successfully, but these errors were encountered: