-
-
Notifications
You must be signed in to change notification settings - Fork 390
🐛 Astro components report props as unused even with ignoreExportsUsedInFile enabled #1629
Description
Prerequisites
- I'm using the latest version
- I've read the relevant documentation
- I've searched for existing issues
- I've checked the list of known issues
- I've read the issue reproduction guide
Reproduction url
https://github.com/JoshuaKGoldberg/repros/tree/astro-knip-ignoreExportsUsedInFile
Reproduction access
- I've made sure the reproduction is publicly accessible
Description of the issue
ignoreExportsUsedInFile should make it so that all interfaces & props that are exported from a file, but also used in that file, are allowed. This works well for UI/site frameworks that allow explicitly defining components with their prop types. For example, in React, export function MyComponent({...}: MyComponentProps { / export const MyComponent: React.FC<MyComponentProps> = ... are fine.
In Astro components, however, the usage of props is implicit. Defining a shape like interface Props { ... } in a .astro file is how to indicate that file's Astro.props is that shape. But because the name Props isn't explicitly typed out in the file, Knip sees it as unused even if ignoreExportsUsedInFile is enabled.
---
export interface Props {
happy?: boolean;
}
// Astro.props is now type Props
---
<main>
<h1>
{Astro.props.happy ? "Hooray!" : "Good."}
</h1>
</main>Proposal: can this be treated as a bug to be fixed?
Originally seen in: https://github.com/flint-fyi/flint/pull/2439/changes#r2937717265