This is my project created by create-nuxt-app.In another project created by vue-cli,Auto completion works right.


Please give a repro case.
Please give a repro case.
Sorry about that,I have updated.
@octref
Does it seem the same from my case #1133, isn't?
@octref The auto completion or IntelliSense works fine when I follow the steps below.
npm i vue,so the package.json will have a vue dependencyThis is a example that works fine.
So, Can vetur make some adjustments to the nuxt project?
I am also experiencing this issue.
Repro (using this starter):
cd /tmp
export PRJ="my-project-ts-test"
vue init nuxt-community/typescript-template $PRJ
cd $PRJ
npm i
code .
code pages/index.vue
Now modify the component to match the following:
export default class extends Vue {
@State people: Person
asyncData(ctx) {
}
}
Now hover on the ctx variable and it is typed as any.

Thank you!
I actually have the same problem on v0.20.0, that this is always any (with Vue.extend(), not class based components). But also without adding any of the Nuxt provided extensions on the component. So I wonder if the typings of Nuxt or other plugins somehow break it.
I actually have the same problem on v0.20.0, that
thisis alwaysany(with Vue.extend(), not class based components). But also without adding any of the Nuxt provided extensions on the component. So I wonder if the typings of Nuxt or other plugins somehow break it.
After install the latest vetur(0.21.0),only add this file to the root directory and all work's fine.
nuxt.d.ts
// 提取自node_modules/@nuxt/vue-app/types 用于解决vetur下AutoCompletion/IntelliSense工作不正常的问题
import Vue from 'vue'
import { Store } from 'vuex'
import VueRouter, { Route } from 'vue-router'
import { MetaInfo } from 'vue-meta'
type Dictionary<T> = { [key: string]: T }
type NuxtState = Dictionary<any>
interface ErrorParams {
statusCode?: number
message?: string
}
interface Context {
app: Vue
/**
* @deprecated Use process.client instead
*/
isClient: boolean
/**
* @deprecated Use process.server instead
*/
isServer: boolean
/**
* @deprecated Use process.static instead
*/
isStatic: boolean
isDev: boolean
isHMR: boolean
route: Route
store: Store<any>
env: Dictionary<any>
query: Route['query']
nuxtState: NuxtState
req: Request
res: Response
params: Route['params']
payload: any
redirect(status: number, path: string, query?: Route['query']): void
redirect(path: string, query?: Route['query']): void
error(params: ErrorParams): void
beforeNuxtRender(fn: (params: { Components: VueRouter['getMatchedComponents']; nuxtState: NuxtState }) => void): void
}
interface Transition {
name?: string
mode?: string
css?: boolean
duration?: number
type?: string
enterClass?: string
enterToClass?: string
enterActiveClass?: string
leaveClass?: string
leaveToClass?: string
leaveActiveClass?: string
beforeEnter?(el: HTMLElement): void
enter?(el: HTMLElement, done: Function): void
afterEnter?(el: HTMLElement): void
enterCancelled?(el: HTMLElement): void
beforeLeave?(el: HTMLElement): void
leave?(el: HTMLElement, done: Function): void
afterLeave?(el: HTMLElement): void
leaveCancelled?(el: HTMLElement): void
}
type Middleware = string | ((ctx: Context, cb: Function) => Promise<void> | void)
declare module 'vue/types/options' {
interface ComponentOptions<V extends Vue> {
asyncData?(ctx: Context): object | undefined
fetch?(ctx: Context): Promise<void> | void
head?: MetaInfo | (() => MetaInfo)
key?: string | ((to: Route) => string)
layout?: string | ((ctx: Context) => string)
loading?: boolean
middleware?: Middleware | Middleware[]
scrollToTop?: boolean
transition?: string | Transition | ((to: Route, from: Route) => string)
validate?(ctx: Context): Promise<boolean> | boolean
watchQuery?: boolean | string[]
}
}
interface NuxtLoading {
fail?(): NuxtLoading
finish(): NuxtLoading
increase?(num: number): NuxtLoading
pause?(): NuxtLoading
start(): NuxtLoading
}
interface NuxtApp {
$loading: NuxtLoading
isOffline: boolean
isOnline: boolean
}
declare module 'vue/types/vue' {
interface Vue {
$nuxt: NuxtApp
}
}
@0njzy0 Sadly, that doesn't work for me. this is still any in my case. I really think the plugins types may break Vetur. When I made a syntax typo in Vue-Apollo yesterday, immediately, this became a vue instance (but at the same time didn't see my props and data because of the syntax error).
I probably will have to setup a test project from scratch and slowly applying my configurations and plugins to find out from which point on Vetur breaks.
Are there any known issues with Visual Studio Code plugins that might interrupt Vetur?
@0njzy0 Sadly, that doesn't work for me.
thisis still any in my case. I really think the plugins types may break Vetur. When I made a syntax typo in Vue-Apollo yesterday, immediately,thisbecame a vue instance (but at the same time didn't see my props and data because of the syntax error).I probably will have to setup a test project from scratch and slowly applying my configurations and plugins to find out from which point on Vetur breaks.
Are there any known issues with Visual Studio Code plugins that might interrupt Vetur?
I clone your project(nuxt-netlify-cms-starter-template),auto completion or intellisense works fine

@0njzy0 Fin, but that's not the project where I face the problem. I have it in a TypeScript project with quite some Vue plugins.
So, as I face this problem with TypeScript while the initial ticket description talks about JavaScript, I might actually have another problem or solution.
What I already did now:
Until here, everything works fine, without moving any typing files, as the tsconfig.json can reference to the typings in the node_modules folder.
What I then did is installing a plugin, namely @nuxtjs/apollo and vue-apollo. Earlier says me to install Vue on top of Nuxt (which seems like wrong). After installing Vue additionally in the Nuxt project (which is not needed out of the box), the typings of Vetur broke, but not the build. Uninstalling Vue then breaks the project for whatever reason. I don't exactly understand how the dependencies work with each other here.
So I repeated the whole steps again, without installing Vue on top of Nuxt and that so far doesn't seem to break Vetur.
All that yet doesn't make any sense to me, so I test a bit further.
@renestalder have you been able to solve this? If not, whats your global typescript version? I've been having this same thing and when i noticed similar issues with type inference on 3.4 typescript version https://github.com/vuejs/vue/issues/9873 I updated typescript globally and it worked fine.
Is this still an issue when you use latest version? Should be resolved by us updating TS dependency.
Hopefully I'm posting under the right issue 🤞
I'm still having this issue on a Nuxt JS project that uses @nuxtjs/apollo. I've narrowed my problem down to apollo property. When I add this to the component it breaks intellisense. I've made a repo to reproduce this problem https://github.com/meatherly/vetur-apollo-intellisense.
If you go to the pages/index.vue file and remove/comment-out the apollo prop then intellisense starts working again in the method increment.
I believe this isn't just @nuxtjs/apollo it seems to be anything that isn't apart of the standard vue component.
Let me know if there is anything I can do to help. Love this extension!
🤦♂️ I just came across this issue and it solved my problem. https://github.com/vuejs/vetur/issues/481
adding a global.d.ts file to the root of my project solved it.
🤦♂️ I just came across this issue and it solved my problem. #481
adding a
global.d.tsfile to the root of my project solved it.
Proper solution is to make your project aware of vue-apollo types.
In your jsonconfig.json or tsconfig.json:
{
"compilerOptions": {
// ...
"types": [
"@nuxtjs/apollo",
"vue-apollo"
]
},
}
🤦♂️ I just came across this issue and it solved my problem. #481
adding aglobal.d.tsfile to the root of my project solved it.Proper solution is to make your project aware of vue-apollo types.
In your
jsonconfig.jsonortsconfig.json:{ "compilerOptions": { // ... "types": [ "@nuxtjs/apollo", "vue-apollo" ] }, }
This will not work with jsconfig.json as types is not supported. In this case the global.d.ts is the only workaround.
What's the reason for using jsconfig.json instead of tsconfig.json? The latter works in JS projects also.
What's the reason for using
jsconfig.jsoninstead oftsconfig.json? The latter works in JS projects also.
yes, you are right of course, I needed to restart vscode.
Correction, as soon as I try to import the vue package typescript intellisense fails. tsconfig.json doesn't seem work with non-typescript projects and vue, see here. Hopefully Vue 3 will change that.
Most helpful comment
After install the latest vetur(0.21.0),only add this file to the root directory and all work's fine.
nuxt.d.ts