Skip to content
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

ts-morph package does not re-export types from @ts-morph/common #1550

Open
kronodeus opened this issue Jun 27, 2024 · 1 comment
Open

ts-morph package does not re-export types from @ts-morph/common #1550

kronodeus opened this issue Jun 27, 2024 · 1 comment

Comments

@kronodeus
Copy link
Contributor

kronodeus commented Jun 27, 2024

Describe the bug

Version: 23.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.

@kronodeus
Copy link
Contributor Author

kronodeus commented Jun 27, 2024

Looks like some types actually are re-exported here: https:/dsherret/ts-morph/blob/latest/packages/ts-morph/src/main.ts

But StandardizedFilePath is not among them. Maybe this one is just missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant