-
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
Module request specifier for a non JS file does not pick up matching definition files #49970
Comments
Isn't this expected as described in following? |
I work with @tomrav, and it's possible we weren't clear enough about our intent in our original post, I hope to make it clearer here. There are a few things we can note:
Furthermore, similar to how esm loaders work in node, bundlers or browsers can also be used to load non-JS files. One example for this is Our repository reproduction demonstrates a case where we have a This raises the question, how can we "type" this Up until now using the // resolution: Node
import * as T1 from "./component.st.css"; // works
import * as T2 from "./component.st.css.js"; // works I think that the Is this the source of the issue?I think it boils down to the fact that
When looking at the
|
Afaik this is pretty much as expected - for any extension that isn't a known js extension that maps to a known extension (eg, js to ts, mjs to mts, cjs to cts), as far as I know, we just append |
Like, the |
Not to go too deeply into implementation details, my logic is:
Same idea is true for the browser and bundlers. I feel like matching definition files that sit next to a source file should not be related to the raw request or the resolution algorithm, but to the resolved file path:
This way when the file |
Hm, I mean, the issue with going with the "always lookup an appended .d.ts extension" route in esm is is means a |
That is why I suggested to also allow just appending Consider the following project structure:
Structure with "conflict":
When adding
There is a reason why you would want to import from I think there is no ambiguity in this kind of matching, and the reason there is the possibility of conflicts in the first place is because the original matching was not for a full extension. When emitting |
@weswigham closed by #51435? |
Bug Report
.d.ts
files are not picked up for files that do not contain a.js
extension in the module request specifier.This happens when using the following configuration:
🔎 Search Terms
definition files, non js, third party
🕗 Version & Regression Information
This reproduces on version
4.7.4
, but I think this issue exists since TypeScript began supporting"type": "module"
configuration.⏯ Playground Link
No playground as this reproduction requires multiple files.
💻 Code
Minimal reproduction repo - https://github.com/barak007/type-module-ts-bug
🙁 Actual behavior
The
component.ts
file, imports thecomponent.st.css
file, but thecomponent.st.css.d.ts
file is not picked up, and the import is not resolved.🙂 Expected behavior
Pick up the module definition for the
.st.css
file and allow using it.The text was updated successfully, but these errors were encountered: