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

TypeScript type error on imports: "The 'accessible-astro-components' library may need to update its package.json or typings." #51

Closed
JoshuaKGoldberg opened this issue Aug 10, 2023 · 6 comments · Fixed by #54
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@JoshuaKGoldberg
Copy link
Contributor

JoshuaKGoldberg commented Aug 10, 2023

In a project using a tsconfig.json with "moduleResolution": "Bundler", trying to import from accessible-astro-components gives a TypeScript type error:

Could not find a declaration file for module 'accessible-astro-components'. '/Users/josh/repos/joshuakgoldberg-dot-com/node_modules/.pnpm/accessible-astro-components@2.1.0/node_modules/accessible-astro-components/index.js' implicitly has an 'any' type.
  There are types at '/Users/josh/repos/joshuakgoldberg-dot-com/node_modules/accessible-astro-components/types/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'accessible-astro-components' library may need to update its package.json or typings.ts(7016)

You can also see that the types are being flagged on https://arethetypeswrong.github.io/?p=accessible-astro-components%402.1.0.

Full repro steps:

git clone https://github.com/JoshuaKGoldberg/joshuakgoldberg-dot-com
cd joshuakgoldberg-dot-com
git checkout 6f8411168447dd6b41e9644ee954c3faa6b822fe
pnpm i

...then open BaseLayout.astro in your editor (e.g. code .).

A couple of resources in case it's helpful:

Oh, and this library is awesome! Thanks for making it 😄

@markteekman
Copy link
Owner

markteekman commented Aug 11, 2023

Hey @JoshuaKGoldberg, thanks for submitting the issue! To be fair, I've got no experience with TypeScript. @david-abell did some incredible work to add TypeScript support to this project. I might look into it when I can find the time, but any help with this would be highly appreciated 😄 And thank you for the compliment, glad you find it useful!

@markteekman markteekman added bug Something isn't working help wanted Extra attention is needed labels Aug 11, 2023
@david-abell
Copy link
Contributor

Hmm @JoshuaKGoldberg I get some git checkout errors with your supplied repo could be bad internet on my end atm. If you change the export key in your local package.json for accessible-astro-components to the below does that resolve the issue?

  "exports": {".": {
    "import": {
      "types": "./types/index.d.ts",
      "default": "./index.js"
  }  
  }},

@JoshuaKGoldberg
Copy link
Contributor Author

git errors

Hmm, the direct URL is https://github.com/JoshuaKGoldberg/joshuakgoldberg-dot-com/tree/6f8411168447dd6b41e9644ee954c3faa6b822fe if that helps.

change the export key

Yup, that fixes it!

@markteekman
Copy link
Owner

Thanks for pitching in @david-abell, you're my TypeScript hero! 😃 And thanks for submitting the solution in a PR @JoshuaKGoldberg 👍🏼

@david-abell
Copy link
Contributor

Thanks @JoshuaKGoldberg @markteekman I got sick while puzzling over how to get these changes to pass "Are the types wrong". Hadn't seen that tool before but I'm impressed by it!

Turns out it was the actual type definition imports at fault but I think I've got a working fix. I should be able to get a PR in for soon.

@markteekman
Copy link
Owner

Thanks @david-abell! Hope you're feeling better now 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
3 participants