Skip to content
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

Support JSDoc name paths in JavaScript #22158

Closed
DanielRosenwasser opened this issue Feb 23, 2018 · 3 comments
Closed

Support JSDoc name paths in JavaScript #22158

DanielRosenwasser opened this issue Feb 23, 2018 · 3 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Domain: JSDoc Relates to JSDoc parsing and type generation

Comments

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Feb 23, 2018

Background

Part of TypeScript's goal is to provide a rich tooling experience. This includes the scenarios where users are

  1. Writing TypeScript which integrates with existing JSDoc'd JavaScript.
  2. Using checkJs on a full JS project to leverage the breadth of .d.ts files on DefinitelyTyped.
  3. Providing a great experience on VS/VS Code/etc. for people who are using JSDoc in loose ways that will hopefully work (or who are willing to put in the effort to get things to work).

We'd like to provide users richer tools that can possibly work for existing code as well.

Basic Proposal

This issue pertains to our JavaScript support via the language service, allowJs, and checkJs.

It tracks understanding some combined set of functionality between JSDoc's namepaths as well as the way in which import paths function in TypeScript today.

For example, the following @typedef tags import the Request and Response interfaces from the module specifiers "express" and "../node_modules/express.Response".

/**
 * @typedef {module:express.Request} Request
 * @typedef {module:../node_modules/express.Response} Response
 */

Since in TypeScript the import specifier "express" could originate from...

  • a folder under node_modules when using "moduleResolution": "node"
  • an ambient module declaration like declare module "express"
  • something which has been path mapped in compilerOptions.paths

we would do the same resolution here for express in module:express.Request.

Open questions:

  1. What about paths with spaces?
  2. How does this work with CommonJS/ESM interop?

What this issue doesn't cover?

While name paths are typically introduced via the the /** @module */ tag (which is not currently supported), this proposal doesn't rely on it. In our brief research, it was unclear whether enough users had a consistent understanding of the tag.

However, one could speculate that the module tag would function similarly to an ambient module declaration. This should be covered in a different proposal.

@DanielRosenwasser DanielRosenwasser added Salsa Domain: JSDoc Relates to JSDoc parsing and type generation labels Feb 23, 2018
@DanielRosenwasser DanielRosenwasser changed the title Support hacky JSDoc module name paths in checkJs Support JSDoc module name paths in checkJs Feb 24, 2018
@DanielRosenwasser DanielRosenwasser changed the title Support JSDoc module name paths in checkJs Support JSDoc module name paths in JavaScript Feb 24, 2018
@DanielRosenwasser DanielRosenwasser changed the title Support JSDoc module name paths in JavaScript Support JSDoc name paths in JavaScript Feb 24, 2018
@aozgaa
Copy link
Contributor

aozgaa commented Feb 26, 2018

For reference, this is a possible solution to #14377.

@DanielRosenwasser
Copy link
Member Author

DanielRosenwasser commented Mar 9, 2018

We're going to hold off on any new JSDoc syntax, and wait for more feedback here. As per #22445, our current recommendation is to wait on #14844 and then use

/**
 * @type {import("express").foo}
 */
let x;

@DanielRosenwasser DanielRosenwasser added the Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature label Mar 9, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Mar 9, 2018

closing in favor of #14844

@mhegazy mhegazy closed this as completed Mar 9, 2018
@mhegazy mhegazy added Declined The issue was declined as something which matches the TypeScript vision and removed Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature labels Mar 9, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Declined The issue was declined as something which matches the TypeScript vision Domain: JSDoc Relates to JSDoc parsing and type generation
Projects
None yet
Development

No branches or pull requests

3 participants