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

IDE type issues with $device helper #136

Open
gregmulvaney opened this issue Mar 3, 2023 · 11 comments
Open

IDE type issues with $device helper #136

gregmulvaney opened this issue Mar 3, 2023 · 11 comments

Comments

@gregmulvaney
Copy link

Webstorm is unable to locate the types for the $device helper. Not really familiar with Nuxt plugins/modules so unfortunately I'm not able to locate the issue. App fails nuxi typecheck as well but is able to be built and functions as expected. Tried adding the module to my tsconfig with no fix.

Nuxt: v3.2.2
device: v3.1.0

@danielroe
Copy link
Contributor

~> nuxt/nuxt#19399

@gregmulvaney
Copy link
Author

gregmulvaney commented Mar 4, 2023

Unless Webstorm is changing something under the hood, I can't see why I would also fail nuxi typecheck with the error of

error TS2339: Property '$device' does not exist on type '{ $: ComponentInternalInstance; $data: {}; $props: Partial<{}> & Omit<Readonly<ExtractPropTypes<{}>> & VNodeProps & AllowedComponentProps & ComponentCustomProps, never>; ... 10 more ...; $watch<T extends string | ((...args: any) => any)>(source: T, cb: T extends (...args: any) => infer R ? (args_0: R, args_1: R) => ...'.

Implementation

<script setup lang="ts">
const { isMobile } = useDevice()
</script>

<template>
  <div class="min-h-[100dvh] flex flex-col">
    <NavDesktop v-if="!$device.isMobile" />

    <div class="mx-auto px-4 container lg:px-8">
      <slot />
    </div>
    <NavMobile v-if="$device.isMobile" />
  </div>
</template>

@danielroe
Copy link
Contributor

No, that shouldn't happen. Would you provide a reproduction?

@gregmulvaney
Copy link
Author

Sure can!

Here is the sandbox: https://codesandbox.io/p/sandbox/great-bash-7zdlg1

Issue persist when running pnpx nuxi typecheck

@danielroe
Copy link
Contributor

danielroe commented Mar 6, 2023

That's a bug with this module (or rather, in the build system), as it does not generate types for its plugin: https://unpkg.com/browse/@nuxtjs/device@3.1.0/dist/runtime/plugin.d.ts.

@nathanchase
Copy link

Yeah, I get a similar error in VSCode:
'__VLS_ctx.$device' is of type 'unknown'.

@joseehilton147
Copy link

joseehilton147 commented Mar 21, 2023

yep, same error on vs code:

image

@max-arias
Copy link

I came across the same issue, I shimmed it by doing:

import { ComponentCustomProperties } from 'vue';

type Device = {
  userAgent: string;
  isDesktop: boolean;
  isIos: boolean;
  isAndroid: boolean;
  isMobile: boolean;
  isMobileOrTablet: boolean;
  isDesktopOrTablet: boolean;
  isTablet: boolean;
  isWindows: boolean;
  isMacOS: boolean;
  isApple: boolean;
  isSafari: boolean;
  isFirefox: boolean;
  isEdge: boolean;
  isChrome: boolean;
  isSamsung: boolean;
  isCrawler: boolean;
};

declare module '@vue/runtime-core' {
  interface ComponentCustomProperties {
    $device: Device;
  }
}

@popdo
Copy link

popdo commented Sep 24, 2023

I get a similar error in VSCode:

'__VLS_ctx.$device' is of type 'unknown'.

@sholohov
Copy link

I solved the problem for myself like this

// plugins.d.ts

import type { Device } from "@nuxtjs/device/runtime/types";

declare module '@vue/runtime-core' {
  interface ComponentCustomProperties {
    $device: Device;
  }
}

@steklopod
Copy link

I solved the problem for myself like this

// plugins.d.ts

import type { Device } from "@nuxtjs/device/runtime/types";

declare module '@vue/runtime-core' {
  interface ComponentCustomProperties {
    $device: Device;
  }
}

That helped, but would be nice to have it out of the box in library

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

8 participants