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

//# typingsURL: comment pragma #43674

Closed
5 tasks done
majo44 opened this issue Apr 14, 2021 · 1 comment
Closed
5 tasks done

//# typingsURL: comment pragma #43674

majo44 opened this issue Apr 14, 2021 · 1 comment

Comments

@majo44
Copy link

majo44 commented Apr 14, 2021

Suggestion

🔍 Search Terms

typings comment pragma import url

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Related issues: #35749, #41730, #33079

The idea is very similar to the //# sourceMappingURL, that JavaScript code file, by self can point to the place where the types declaration related to current source is located. And as the sourceMappingURL the value for the pragma can be a relative path, url, or the inline data url. This will plays well with the individual es modules as well as with the bundles.

📃 Motivating Example

If typescript compiler on one hand will allows to generate the //# typingsURL on on the other will read such pragma from the imported sources this will

  • Simplify the work with the URI style import as just by the same URL import we will get the production code, and the types declaration.
  • Helps with the NodeJS 12.7+ package exports as we will not need anymore to put the typings property to the package.json and to exports declaration

💻 Use Cases

  • For TypeScript to find definition file for imports which targets directly code (not declaration, not package), especially in case when the URL style import will be used.
  • Such approach can be easy consumed by the IDE (intellisense, documentation), deno, bundlers, ect ...
@andrewbranch
Copy link
Member

The compiler really doesn’t want to parse (or even read) (much less download) JS that it doesn’t need to, which we would have to do in order to read the comment. You’re right that resolving typings for URL imports is something we’ll have to think about. But we’ll figure out the implementation details as part of implementing whole features/scenarios. Thanks for the input!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants