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

Re-exported type reported as unused with ignoreExportsUsedInFile #622

Closed
haines opened this issue May 3, 2024 · 3 comments
Closed

Re-exported type reported as unused with ignoreExportsUsedInFile #622

haines opened this issue May 3, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@haines
Copy link

haines commented May 3, 2024

Repro: https://stackblitz.com/edit/github-hqqlbk?file=component%2Findex.ts

We have a standard module template for our React components, so that every component (at least) exports its props and the component itself, like

// component.ts
export interface ComponentProps { ... }
export default function Component(props: ComponentProps) { ... }

This works fine with Knip even if nothing imports the props, as long as ignoreExportsUsedInFile is set to true.

However, it doesn't work on our wrapper components, where we re-export the props from an internal file

// index.ts
import { ComponentProps } from "./component";

export type { ComponentProps };
export default function Wrapper(props: ComponentProps) { ... }

I would have expected in this case that ComponentProps would not be reported as an unused export from index.ts because of ignoreExportsUsedInFile, but it was:

$ npm run knip

> @knip/[email protected] knip
> knip

Unused exports (1)
ComponentProps  unknown  component/index.ts:4:9
@haines haines added the bug Something isn't working label May 3, 2024
@webpro webpro closed this as completed in 7b4da85 May 4, 2024
@webpro
Copy link
Collaborator

webpro commented May 4, 2024

Thanks for the report, @haines. The issue is that the usage of ComponentProps refers to the import, not the export. But a strict re-export wouldn't be an import, and therefore no usage would be possible. So I've tried to come up with a fix.

@webpro
Copy link
Collaborator

webpro commented May 4, 2024

🚀 This issue has been resolved in v5.12.2. See Release 5.12.2 for release notes.

Using Knip in a commercial project? Please consider sponsoring me.

@haines
Copy link
Author

haines commented May 4, 2024

Awesome, thanks for fixing it so quickly! I've tried out 5.12.2 and it no longer reports these cases 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants