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 typings missing? #67

Open
Parakoos opened this issue Mar 27, 2021 · 2 comments
Open

Typescript typings missing? #67

Parakoos opened this issue Mar 27, 2021 · 2 comments

Comments

@Parakoos
Copy link

Hi,

I followed the install instructions. So, I have:

// package.json
"devDependencies": {
  "@nuxtjs/device": "^2.0.1",
},

//  nuxt.config.ts
buildModules: [
  '@nuxt/typescript-build',
  '@nuxtjs/vuetify',
  '@nuxtjs/pwa',
  '@nuxtjs/firebase',
  '@nuxtjs/device',
],

And yet, I do not get any type-ahead typings anywhere. I tried in the store, on the nuxt Context object and a component's 'this'. No $device object found anywhere. If I run the app and inspect it with the Chrome dev tools, I can see it is there. And, if I do the following, it works!

// Inside a component (using property decorator syntax)
get isOnDesktop() {
  return (this as any).$device.isDesktop
}

I've even restarted windows just to make sure it wasn't something weird like that.

Where am I going wrong?

@teaknig
Copy link

teaknig commented Jun 4, 2021

types are missing here, so you have to solve the problem by yourself

create a file vue.d.ts

and copy there

// ./vue.d.ts

// eslint-disable-next-line @typescript-eslint/no-unused-vars
import Vue from 'vue'

interface IDevice {
  isDesktop: boolean
  isMobile: boolean
  // etc
}

declare module 'vue/types/vue' {
  interface Vue {
    $device: IDevice
  }
}

declare module '@nuxt/types' {
  interface NuxtAppOptions {
    $device: IDevice
  }
}

@teaknig
Copy link

teaknig commented Jun 4, 2021

sorry

types exist, you need tsconfig.json

{
   "compilerOptions": {
    ...
      "types": [
        "@nuxtjs/device"
      ]
    ...
  }
}

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

3 participants