create-nuxt-app icon indicating copy to clipboard operation
create-nuxt-app copied to clipboard

Typescript: project should include a definition file for files with .vue extension

Open lambda0xff opened this issue 5 years ago • 7 comments

Projects using typescript should include a definition file: vue-shim.d.ts

declare module "*.vue" {
  import Vue from 'vue'
  export default Vue
}

this allows importing .vue modules inside .ts files ( for unit tests for instance)

lambda0xff avatar Apr 09 '20 19:04 lambda0xff

Let’s see what @kevinmarrec thinks about this :)

atinux avatar Apr 09 '20 21:04 atinux

It's mentionned in documentation : https://typescript.nuxtjs.org/guide/setup.html#configuration

You will also need to provide types for Vue files by adding the following type declaration ...

kevinmarrec avatar Apr 09 '20 21:04 kevinmarrec

Documentation ... who has time to read them ? 😁😜

More seriously, why not add that file directly when typescript is selected ?

lambda0xff avatar Apr 09 '20 21:04 lambda0xff

Oh yeah nvm it should be indeed added by CNA :)

kevinmarrec avatar Apr 09 '20 21:04 kevinmarrec

Adding it to the repo will indeed be helpful as now doing it with documentation gives error:

Parsing error: Imports within a `declare module` body must always be `import type` or `import typeof`

...and trying to modify piece from docs to be:

declare module '*.vue' {
    import type Vue from 'vue';
    export default Vue;
}

...gives following error:

Parsing error: Only declares and type imports are allowed inside declare module

Reeywhaar avatar Apr 29 '20 04:04 Reeywhaar

@Reeywhaar

This PR adds it : https://github.com/nuxt/create-nuxt-app/pull/449

And about your error, I never had this one, I think you have a mistake in your configuration, please open a new issue on TypeScript repo with reproduction so I can find a fix for you.

kevinmarrec avatar Apr 29 '20 07:04 kevinmarrec

@Reeywhaar I think it's babel error, you maybe didn't see Warning in : https://typescript.nuxtjs.org/guide/lint.html#configuration

kevinmarrec avatar Apr 29 '20 07:04 kevinmarrec