-
Notifications
You must be signed in to change notification settings - Fork 1
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
@typedef scopes #31
Comments
I can't seem to find conclusive evidence for or against that. the documentation for I suspect the scope-related tags are really meant for code documentation generation tools like swagger, but that suspicion is also something for which I can't find any evidence.
given the following two files: // foo.js
/**
* @typedef {string} Foo
*/
// index.js
import './foo';
/** @type {Foo} */
const x = 'foo type'; I don't see how we can discover the
yep, exactly. behind the scenes, typedefs are tied to their containing file; it's to distinguish between the following example is not something supported by this plugin today, I don't think, but is supported in my IDE and is how I document things in other projects: /**
* @return {import('../types').Foo}
*/
function myFunc() {
return { name: 'Alice', age: 25 };
} if I use an external type many times in one file, I'll re-typedef it: /** @typedef {import('../types').Foo} Foo */
/**
* @return {Foo}
*/
function myFunc() {
return { name: 'Alice', age: 25 };
} it's not ideal, but neither is scanning your entire source tree to discover |
I think you're already rescanning it when you hit an import. You could change it to only rescan the magic import(foo).bar type syntax, which would reduce it to the tree of type related modules, but you can't avoid that since you need properties of the imported type beyond the name. Given that, I suggest you might as well keep it simple and follow imports as is. I'll take a futher look at @global, but jsdoc is a mess. :) |
l found the test cases in jsdoc, and I think I see how it must work now. https://github.com/jsdoc/jsdoc/blob/master/packages/jsdoc/test/fixtures/typedeftag.js In this case it follows. I'll put in a PR for jsdoc to add an @global @typedef test case to nail down the semantics. |
I also found this existing test case.
as in the test file for CalculatorBattery
So I think the current behavior on eslint-plugin-typelint is non-conformant with jsdoc. Supporting and adding /** @module */ at the start of the file should produce similar behavior to what we have at the moment, although I think the prefix needs changing for that case. |
I've added test cases to jsdoc in jsdoc/jsdoc#1801 At least for jsdoc the following are true a.js
x has global scope, and has qualified name "x". b.js
b has inner scope, and a qualified name of "module:b~b". c.js
c has global scope and has qualified name "c". d.js
Has inner scope and the qualified name "module:[[string0]]~d". Which at least makes it clear what the semantics for jsdoc are. :) |
Ah, now I see where this is coming from -- it looks like it's a typedoc thing rather than a jsdoc thing.
https://github.com/christopherthielen/typedoc-plugin-external-module-name |
what would you like to see added?
I've been reading about scopes, and I'm not entirely sure that I understand fully how it's supposed to work.
This looks to me as though it ought to create a global typedef, which can be referred to as Foo in any location.
In which case, a simple import './foo'; should be enough to link it in.
There is also /** @module */ which will derive a module name from the current file, unless specified.
It kind of looks like we are effectively inserting an implicit /** @module */ at the top of each file.
I'm not sure if this is correct -- without it, should @typedefs belong in the global scope?
The text was updated successfully, but these errors were encountered: