-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
"composite: true" ignores existing .d.ts files for .js sources #47035
Comments
The workbench example doesn't really show me what's going on here. Can you make a sample repo? Note: It's unlikely you're seeing a bug here; this sounds like a misconfiguration or misunderstanding |
From the workbench example, switch to the "Debug" tab, scroll down to "Virtual file system", and observe the generated foo.d.ts file, see screenshot https://i.imgur.com/blG8QMO.png. It should say |
I don’t think TS uses |
I think you have misunderstood the issue here. TS claims that one should be able to use In other words TS uses a .js file to generate a .d.ts file when it shouldn't, because a .d.ts file is already provided. [1] https://www.typescriptlang.org/docs/handbook/project-references.html |
The workbench repro isn't great because the root cause of the problem here is that the It's never the case that we copy a It's also never the case that we use a The way this is "supposed" to work is that the referencing project would import into the referenced project, and get redirected to that project's output .d.ts files which are autogenerated from the JS files. I don't see a bug here unless something has specifically regressed; this behavior has been in place since 3.0 and it's unlikely you've stumbled into something no one else has noticed in the intervening years. |
Perhaps I have dumbed down this minimal example more than I should, to the point where the validity of this bug is not clear. I'll create a full repo then to showcase the problem, but the end result is that a project that uses Note that this problem was discovered as part of TS work happening in the Chromium repository where we have a tsconfig that uses fuse.js+fuse.d.ts (from https://www.npmjs.com/package/fuse.js), and then trying to refer to that tsconfig from another tsconfig. TS generates d.ts from fuse.js which is a mangled+minimized file to begin with and results in incorrect d.ts, compared to the manually provided fuse.d.ts file. Again, I think this will become clearer with a full repro instead of a minimal example (I'll ping this thread once I have a sample repo ready). |
- Add "composite: true" to c/b/r/tab_search:build_ts - Add workaround for microsoft/TypeScript#47035. - Pass all test files to ts_library(), while still using JS. - Serve tests from chrome://webui-test/ - Move tests from browser_tests_js_webui to browser_tests_js_mojo_webui, since it is more appropriate. - Use absolute chrome://webui-test/test_util.js and chrome://webui-test/chai_assert.js paths. These are in preparation of actually migrating files from JS to TS. Bug: 1260300,1260297 Change-Id: Ib5dd46535a8d0c916973844155d2824418dc926a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3319713 Reviewed-by: Thomas Lukaszewicz <[email protected]> Commit-Queue: Demetrios Papadopoulos <[email protected]> Cr-Commit-Position: refs/heads/main@{#949441}
@RyanCavanaugh: Please see sample repository showcasing the problem at https://github.com/freshp86/typescript-issue-47035. Repro instructions are in the README.md file. Hopefully this makes it easier to assess the problem being reported here. |
OK, I see what's happening here. TL;DR this setup is not supported. When module resolution lands on a file that is a source input of a referenced project, TypeScript uses that project's tsconfig to instead load the emitted declaration file for that source input. In your case, that means module resolution found If you want this to work, I think the only solution is just a general "do something differently", since the setup here is effectively tricking TypeScript into thinking that something different is happening than it expects. I'd move |
Thanks for looking into this and for the suggestions. Some comments below
Ack. My earlier claim was that TS should not emit a new declaration file when a manual one is already provided side-by-side with the input source file. You have addressed that earlier with the following comment
Overall it feels that Note that in our real world scenario in the Chromium repo
Ack. That's very similar to what we've done so far as a workaround at [1], where
Sounds like the workaround is the long term fix here. It still feels that this setup should be supported. Having Either way since there is a reasonable workaround, feel free to close this report. [1] https://chromium-review.googlesource.com/c/chromium/src/+/3319713 |
This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow or the TypeScript Discord community. |
Bug Report
When using
composite: true
to refer from a project A to project B TypeScript generates .d.ts files for all the files in project B, even for .js files that already have user-provided d.ts files.🔎 Search Terms
composite, definition, generate
🕗 Version & Regression Information
Reproducing on 4.2.3 (did not try older versions)
⏯ Playground Link
Workbench Repro
🙁 Actual behavior
TypeScript generates a new
foo.d.ts
file based onfoo.js
instead of reusing the existingfoo.d.ts
. In the toy example above, note that the return type offoo()
is inferred from the code asnull
.🙂 Expected behavior
TypeScript should reuse the existing
foo.d.ts
, instead of trying to infer a new one fromfoo.js
. In the toy example above the return type offoo()
should bestring
as is already declared in the input filefoo.d.ts
. Note that in a real-world example the inferred d.ts file can be incorrect causing problems when other projects try to consume it by usingcomposite: true
and project references.The text was updated successfully, but these errors were encountered: