Minimal example: https://github.com/ImanMh/ts-import-types-issue
You can find 2 commits. The first one is the initialization commit and it works fine. Ignore that. The second one is an example where consumers of this package can import the two function (sum and concat) and happily use it, but the types don't work due to issues in the generated d.ts file.
These are 2 separate problems but I guessed maybe the are being originated from the same source. You can link this package locally and see yourself that the types are not working. Here is an output of the generated type file:
import { sum } from 'math/sum';
import { concat } from 'string/concat';
export { sum, concat };
Expected behavior
If I want to make this work in other consumer projects, I should change the type file like this:
import { sum } from './math/sum/sum';
import { concat } from './string/concat';
export { sum, concat };
Then it works perfectly. The issue with the ./ at the beginning of files appear when you use "baseUrl": "./src" in your tsconfig. If I want to remove it then I'll end up with ugly paths everywhere.
The issue with './math/sum' appears when I add a package.json file inside sum directory. here is the content of the package.json file:
{
"main": "sum.ts"
}
In the output file this package.json file is removed so there is no way for the compiler to know where to find the sum.ts .
Suggested solution(s)
consider ./ at the beginning of the output index.d.ts and concat package.json.main to the end of the paths of any directory.
Additional context
I hope I'm not missing something obvious. I know that this issue might be related to TS itself and not TSDX but I just wanted to make sure and discuss it with you.
Current Behavior
Minimal example: https://github.com/ImanMh/ts-import-types-issue You can find 2 commits. The first one is the initialization commit and it works fine. Ignore that. The second one is an example where consumers of this package can import the two function (sum and concat) and happily use it, but the types don't work due to issues in the generated d.ts file.
These are 2 separate problems but I guessed maybe the are being originated from the same source. You can link this package locally and see yourself that the types are not working. Here is an output of the generated type file:
Expected behavior
If I want to make this work in other consumer projects, I should change the type file like this:
Then it works perfectly. The issue with the
./
at the beginning of files appear when you use"baseUrl": "./src"
in your tsconfig. If I want to remove it then I'll end up with ugly paths everywhere.The issue with './math/sum' appears when I add a package.json file inside
sum
directory. here is the content of the package.json file:In the output file this package.json file is removed so there is no way for the compiler to know where to find the sum.ts .
Suggested solution(s)
consider
./
at the beginning of the output index.d.ts and concat package.json.main to the end of the paths of any directory.Additional context
I hope I'm not missing something obvious. I know that this issue might be related to TS itself and not TSDX but I just wanted to make sure and discuss it with you.
Your environment