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

Types imported from Astro file are not working correctly #341

Open
2 tasks done
nix6839 opened this issue Apr 3, 2024 · 1 comment
Open
2 tasks done

Types imported from Astro file are not working correctly #341

nix6839 opened this issue Apr 3, 2024 · 1 comment

Comments

@nix6839
Copy link
Contributor

nix6839 commented Apr 3, 2024

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

  • I have tried restarting my IDE and the issue persists.
  • 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.

@ota-meshi
Copy link
Owner

@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

@nix6839 nix6839 changed the title Error with @typescript-eslint/no-unsafe-assignment Types imported in an Astro file are not working correctly Apr 3, 2024
@nix6839 nix6839 changed the title Types imported in an Astro file are not working correctly Types imported from an Astro file are not working correctly Apr 3, 2024
@nix6839 nix6839 changed the title Types imported from an Astro file are not working correctly Types imported from Astro file are not working correctly Apr 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants