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

"Failed to resolve import source - TypeScript modules" #27703

Closed
mkalinski93 opened this issue Jun 19, 2024 · 1 comment
Closed

"Failed to resolve import source - TypeScript modules" #27703

mkalinski93 opened this issue Jun 19, 2024 · 1 comment

Comments

@mkalinski93
Copy link

mkalinski93 commented Jun 19, 2024

Summary (generated):

Here is a brief summary in English:

Operating system: Darwin. Node version: 21.7.1. Nuxt version: 3.11.2.

A TypeScript file is created in the "types" folder, declaring a module "components/logo" and an interface "LogoProps".

Trying to import this type into a component results in the bug that only exported interfaces work, not declared modules.

There is no additional context or logs provided.


Environment


  • Operating System: Darwin
  • Node Version: v21.7.1
  • Nuxt Version: 3.11.2
  • CLI Version: 3.11.1
  • Nitro Version: 2.9.6
  • Package Manager: npm@10.5.0
  • Builder: -
  • User Config: modules, css, tailwindcss, primevue
  • Runtime Modules: @primevue/nuxt-module@4.0.0-rc.2, @nuxtjs/tailwindcss@6.12.0, @vueuse/nuxt@10.11.0
  • Build Modules: -

Reproduction

Create a typescript file in the "types" folder

"components.ts"

declare module "components/logo" {
    export interface LogoProps {
        width?:string;
    }
}

try to import the type into a component
"component.vue"

<script setup lang="ts">
import type {LogoProps} from 'components/logo'

withDefaults(defineProps<LogoProps>(), {
  width: '32px'
});
</script>

Describe the bug

It doesn´t seem to be possible, to add declared modules in a component. Only exported interfaces seems to be working fine.

Additional context

No response

Logs

No response

@nuxtbot nuxtbot changed the title Failed to resolve import source - typescript modules "Failed to resolve import source - TypeScript modules" Jun 19, 2024
@danielroe
Copy link
Member

danielroe commented Jun 19, 2024

you just do export type, no need for the declare module bit.

Here's an example. Bear in mind you need to install typescript and vue-tsc as dependencies:

https://stackblitz.com/edit/github-ewqayl?file=app.vue,types/components.ts

edit: I see you are aware of this. The reason is that the vue compiler doesn't know anything about these module declarations. You can provide that file as a 'global type file' to vue in Vue options, but it's a bit complex. How necessary is that to you?

@danielroe danielroe closed this as not planned Won't fix, can't repro, duplicate, stale Jun 19, 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