ts-morph package does not re-export types from @ts-morph/common
Describe the bug
Version: 26.0.0
If you are exporting types from your project that are using inferred types from @ts-morph/common, you'll get compiler errors when using package managers like pnpm which have stricter behavior around transitive dependencies.
To Reproduce
Create a typescript project that depends on ts-morph and export a function like this:
import { Project, SourceFile } from "ts-morph";
const project = new Project();
const file = project.createSourceFile("test.ts", ``);
export function getSourceFilePath() {
return file.getFilePath() // Inferred return type is StandardizedFilePath from @ts-morph/common
}
If you're using a package manager like pnpm, compiling the project should produce an error like this:
src/Example.ts:6:17 - error TS2742: The inferred type of 'getSourceFilePath' cannot be named without a reference to '.pnpm/@ts-mor
[email protected]/node_modules/@ts-morph/common'. This is likely not portable. A type annotation is necessary.
6 export function getSourceFilePath() {
~~~~~~~~~~~~~~~~~
The only way to resolve this is to declare a direct dependency on @ts-morph/common which, as specified in that package's readme, you are NOT supposed to do and shouldn't need to.
Expected behavior
I should not need to depend directly on @ts-morph/common in order to export inferred types from ts-morph. The solution (as mentioned in this thread) is to re-export types from @ts-morph/common in ts-morph so that that can be used directly by dependent projects.
Looks like some types actually are re-exported here: https://github.com/dsherret/ts-morph/blob/latest/packages/ts-morph/src/main.ts
But StandardizedFilePath is not among them. Maybe this one is just missing.
Hello I've ran into this as well. @kronodeus have you tried patching locally to see if that fixes the problem?
Hello I've ran into this as well. @kronodeus have you tried patching locally to see if that fixes the problem?
Yes, monkey patching by re-exporting StandardizedFilePath fixed the issue back when I was looking into this. But we opted to take a direct dependency on @ts-morph/common instead