eslint-plugin-astro icon indicating copy to clipboard operation
eslint-plugin-astro copied to clipboard

Types imported from Astro file are not working correctly

Open nix6839 opened this issue 10 months ago • 1 comments

Before You File a Bug Report Please Confirm You Have Done The Following...

  • [X] I have tried restarting my IDE and the issue persists.
  • [X] I have updated to the latest version of the packages.

What version of ESLint are you using?

8.57.0

What version of eslint-plugin-astro are you using?

0.33.1

What did you do?

Configuration
module.exports = {
  extends: [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended-type-checked",
    "plugin:astro/recommended"
  ],
  parserOptions: {
    project: "./tsconfig.json",
  },
  overrides: [
    {
      files: ["*.astro"],
      parser: "astro-eslint-parser",
      parserOptions: {
        parser: "@typescript-eslint/parser",
        extraFileExtensions: [".astro"],
      },
    }
  ]
}
---
// Exported.astro
export type { Props as ExportedProps };

interface Props {
	pageName: string;
}
---
---
// ErrorComponent.astro
import type { ExportedProps } from './Exported.astro'

interface Props {
	pageName: ExportedProps['pageName'];
}

const { pageName } = Astro.props;
---

<h1>{pageName}</h1>

What did you expect to happen?

const { pageName } = Astro.props;

pageName has a string type, so it should not throw any lint errors related to type any.

What actually happened?

Unsafe array destructuring of a tuple element with an `any` value  @typescript-eslint/no-unsafe-assignment"

Link to Minimal Reproducible Example

https://eslint-online-playground.netlify.app/#eNq1UsFu2zAM/RVBlwBDLTdLgw5eN2zYsuO2e92DITOp0lgSJLXoEPjfR4lW6rRu0R56SWCS7/G9R+25d7JcOWfcD9NZo0EH0fjgDK94URS1Vlh1gYV/Ftiere7jF7R/nbGe9WztTMdmosx1ws4+17os2RuhwUccbtQB3LqRwGh0j8Vgmw38bjqojnkuZ7kxu0JwH/HSaB9wYe7gri/se9QlbMTgXHJW64vr+dd9HusvSvysNT+hTI4c5TQgVbMl0tf4x95eYwNZld6Q5kSNe4NH7Wu1EVtvNK5MkJrDfQDd+ppXrOZJTpknfRl5JA4losfag0eW99GMqwT4HSKcFHIbF3Wmvd2BoH0eQ0c4Y4P6il3GL4YWCFY5kKbrsAdtzU9y0+5uN0pX36JcL52yoaD5cjRfxG4hr0HeTIEpoyP+OHGV5mzjPLg/Nih8JxVpxKozW5AhJiwO6aY7DPR9+jV34Jxq4cHOgGdsrXZU5h/ozdScFib6tPRwv8FSQeWDgefEHTNMRPOEJ8Xuml+oaRXz98SH4p5qI2f4nzLKx7WNvMHDj55iDLgFGwPVUkF6j4PAwRa90DOxFPOPFDlxR9zdz+egL/iJdOdIdzq68cR4TjNdfxpFI9T7JJbnE80BX4ysnIrFQsxHkw+7aWApzsRisErJ9f8BjLHMyA==

Additional comments

There are no lint errors when using types exported from a .ts file instead of an .astro file. You can check this by uncommenting in the reproduce link.

nix6839 avatar Apr 03 '24 00:04 nix6839

@typescript-eslint/parser cannot import types other than those in ts files. Could you try typescript-eslint-parser-for-extra-files instead? It's an experimental project to solve that problem. https://github.com/ota-meshi/typescript-eslint-parser-for-extra-files

ota-meshi avatar Apr 03 '24 01:04 ota-meshi