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

Type issue when importing module #274

Closed
ps-20x opened this issue Apr 29, 2024 · 4 comments
Closed

Type issue when importing module #274

ps-20x opened this issue Apr 29, 2024 · 4 comments

Comments

@ps-20x
Copy link

ps-20x commented Apr 29, 2024

Environment

  • Operating System: Darwin
  • Node Version: v18.20.2
  • Nuxt Version: 3.11.2
  • CLI Version: 3.11.1
  • Nitro Version: 2.9.6
  • Package Manager: npm@10.5.0
  • Builder: -
  • User Config: devtools
  • Runtime Modules: -
  • Build Modules: -

Reproduction

  1. Checkout https://github.com/ps-20x/phpstorm-issues
  2. Run npm ci
  3. Open utils/createSitemapItem.ts
  4. Import type shows an error

Describe the bug

The following error is showing up:

Vue: Cannot find module @nuxtjs/sitemap/dist/runtime/types or its corresponding type declarations.

Additional context

Tried it in PHPStorm as well as in VSCode. The project is an almost plain project.

PHPStorm
image

VSCode
image

You can check out more information on the type issues here: https://arethetypeswrong.github.io/?p=@nuxtjs/sitemap@5.1.4 (thanks to @danielroe)

This issue was initially raised in the nuxt repository: nuxt/nuxt#26955

@harlan-zw
Copy link
Collaborator

harlan-zw commented Apr 29, 2024

Please follow the docs and use the util function to extract the types, see https://nuxtseo.com/sitemap/guides/dynamic-urls#_2-create-your-own-endpoint

createSitemapItem = function() {
  return asSitemapUrl({ ... }) // types will just work
}

Type support via dist runtime is not supported from the nuxt-module-builder currently afaik. There is a work around for this but the sitemap module has not implemented it yet.

@ps-20x
Copy link
Author

ps-20x commented May 6, 2024

Please follow the docs and use the util function to extract the types, see https://nuxtseo.com/sitemap/guides/dynamic-urls#_2-create-your-own-endpoint

Thanks for your suggestion and help.

This worked for my SitemapUrl. But I can't figure out on how to get types for the values in there.

// works
type SitemapUrl = ReturnType<typeof asSitemapUrl>;
// does not work
type Priority = SitemapUrl["priority"];
type Changefreq = SitemapUrl['changefreq'];

I am getting the message:

Property priority does not exist on type SitemapUrlInput

@harlan-zw
Copy link
Collaborator

I've pushed up some improvements in v5.1.5 for the types.

An alias is now added that points to the runtime types directly, it's at #sitemap.

import type { SitemapUrl } from '#sitemap'

Let me know if you have any issues.

@ps-20x
Copy link
Author

ps-20x commented May 7, 2024

I've pushed up some improvements in v5.1.5 for the types.

An alias is now added that points to the runtime types directly, it's at #sitemap.

import type { SitemapUrl } from '#sitemap'

Let me know if you have any issues.

Worked perfectly thank you 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants