-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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] Provide a JSDoc equivalent of import { ..} from "mod"
#14377
Comments
I hit the same issue today, the idea is to not relying on transpiling on server side, for example, I want to define my own object type like this, below does not work: /**
* @typedef {Object} Watcher
* @property {string} dir
* @property {fs.FSWatcher} watcher
*/ The editor complains that it does not understand |
We will proceed with #14056 for now, try to special case classes. |
Such a workflow would also be brilliant for Angular1 apps where you may have a main file that injects all your dependencies and a separate file that specifies your controller. The controller file exports a function/class. It receives its dependencies but does not inject them directly, being able to tag them using JSdoc as a type that was defined in a different file in your workspace would be invaluable there. |
@mhegazy did you ever get anything working along these lines? Trying to reference a js class from a typedef, sounds like the same problem. |
Any progress here? |
Maybe? /**
* @import {File} from './file'
*/
/**
* @param {File} file
*/
getFile(file) {
} |
Helo, was there any update on this? It would be great to have this. |
Having a straightforward way to do this is a must in any decent code design where one needs to inject a dependency. Any updates, please? |
Any update on this? |
I suggest we use the same syntax as Closure does:
https://github.com/google/closure-compiler/wiki/JS-Modules#type-references You can also write the syntax as |
Sadly, the conversation has not gone far to implement this feature:( Very much looking forward to having this added. |
Is/Can the following case be covered/coverable? type of In the following code devServer is still identified as
|
You could put in a PR against DefinitelyTyped to fix |
Thanks for the hint; When extracted, the following case displays
|
Unfortunately, this code breaks my jsdoc generation: /**
* @typedef {import("./foo").Bar} Bar
*/ Results into:
when I execute jsdoc. Could you give any hints on how to keep my jsdoc working? |
looks like a request for your jsdoc generation tool. |
@mhegazy Does not seem like that work Currently now only this below work |
you have declared a type alias called consider adding a .d.ts file in your project with a declaration for // globals.d.ts
declare var firebase: typeof import("firebase"); also |
@mhegazy It is still the same that it need to have d.ts separate from js while I would like to declare in js purely (or don't even need to declare anything if possible) ps. The |
@mhegazy Also if I put the It work fine here Until I close the file edit: Seem like this was cause from putting that |
Make sure you add a |
This issue is encompassed in jsdoc/jsdoc#1537. JSDoc is not a very active project so I think it's unlikely to add support for this functionality. Unfortunately, this makes it very difficult to migrate vanilla JavaScript to TypeScript type checking while still appeasing JSDoc stakeholders wary of change since the new syntax breaks JSDoc execution. I've experimented with If it were supported, the |
@joma74 You could actually do the following: /**
* @type {import('webpack').Configuration & { devServer: import('webpack-dev-server').Configuration }}
*/
var webpackConfig = {
devServer: {
port: 8080,
watchContentBase: false,
hot: true,
stats: 'errors-only',
host: '0.0.0.0',
},
// ...
}; |
I made this file in project and it was add to However the JSDoc does not register the class in namespace loaded this way |
Can you share a project i can look at? |
I'm surprised that this was closed as "fixed", when the intent was to "provide a JSDoc equivalent of ...".
As already pointed out by #14377 (comment), it would be great to have a real equivalent that could would simultaneously let Typescript-in-Javascript know about the ❤️ |
Sadly, we still have nothing good to use? :( |
It would be great if this issue could be reopened to continue discussion and not let it get lost. |
Do even JSDoc have an official syntax for type import? |
Is there an way to reference an class as an argument without importing it? EDIT: For now only this worked for me /** @typedef {import('../my-class').default} MyClass */ |
I did a little patch in JSDoc to does not breaks and accepts |
Given an implementation of a class:
How can you use the type without importing the module:
One option is to use
@module
e.g.:
The text was updated successfully, but these errors were encountered: