Open lucacasonato opened 4 months ago
The
.ts
files are included in the published package to enable "Go to source definition" for users. Is it really necessary to place all generated files into a separate directory?
Yes. A .ts
is always preferred over the .d.ts
. The declaration file is considered a build artifact of the TypeScript file.
See also https://github.com/microsoft/TypeScript/issues/56412#issuecomment-1852647507 and #15272.
Also worth noting is that "Go to source definition" only works at all because the TS language service prefers to load the .ts
over the .d.ts
This is currently expected behavior, but I do think we should explore changing it. This happens to avoid loading your own output files as part of your input files, but it doesnβt make a lot of sense to do for files that you didnβt emit, e.g. declaration files in node_modules
.
I'm confused how this project even builds. The inclusion of this .ts
file should have been a rootDir
and/or composite
violation, and we should be trying to emit a .d.ts
file for it.
Can we get a sample repo?
If file is imported from node_modules
its not considered for "rootDir" and "composite" calculations as it wont be emitted
I'll set up a reproduction repo tomorrow
Made a small reproduction, instructions are in the README: https://github.com/lucacasonato/typescript-issue-58353
Our workaround for this was emitting both the .js
and .d.ts
files into a separate directory, but this has other issues (namely import.meta.url
is now wrong for users, e.g https://github.com/jsr-io/jsr/issues/477).
We'll try again here, by only emitting .d.ts
files into a subdirectory, and keeping the .js
files next to the .ts
files - I think this will work, because we can already rewrite specifiers in the .d.ts
files, but it'll be weird.
π Search Terms
π Version & Regression Information
TypeScript 5.4.3
β― Playground Link
No response
π» Code
π Actual behavior
From the
walk.d.ts
file (referenced specified inpackage.json
"types"
conditional export), a type is imported from./_create_walk_entry.d.ts
. TypeScript however does not load./_create_walk_entry.d.ts
, but instead loads./_create_walk_entry.ts
(and then tries to check it) even though./_create_walk_entry.d.ts
exists. Why?The
.ts
files are included in the published package to enable "Go to source definition" for users. Is it really necessary to place all generated files into a separate directory?π Expected behavior
No
.ts
file to be loaded, because all specifiers (both in conditional exports, and in declaration files) reference.d.ts
files.This is especially the case because when
declaration: true
is specified, TypeScript will by default place.js
and.d.ts
directly next to the.ts
code. If you publish this to npm, it will not work.Additional information about the issue
No response