Skip to content

🐛 Astro components report props as unused even with ignoreExportsUsedInFile enabled #1629

@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Prerequisites

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions