question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`useStorage` got ts error TS2339

See original GitHub issue

In my nuxt 2 project

import { computed, Ref } from '@vue/composition-api'
import { useWindowSize, createGlobalState, useStorage } from '@vueuse/core'

export const useVerticalSizeState = createGlobalState(() =>
  useStorage(
    'use-vertical-size',
    {
      aspectRatio: 9 / 16,
    },
    sessionStorage,
  ),
)

export function useVerticalSize() {
  const { width: windowWidth, height: windowHeight } = useWindowSize()
  const state = useVerticalSizeState()

  const aspectRatio = computed(() => state.value.aspectRatio)
  const width = computed(() =>
    Math.min(windowWidth.value, windowHeight.value * aspectRatio.value),
  )
  const height = computed(() => windowHeight.value)
  const setAspectRatio = (aspectRatio: Ref<number>) => {
    state.value.aspectRatio = aspectRatio.value
  }

  return {
    width,
    height,
    aspectRatio,
    setAspectRatio,
  }
}

got this error

ERROR in utils/useVerticalSize.ts:21:44
TS2339: Property 'value' does not exist on type 'Omit<Ref<{ aspectRatio: number; }>, "value">'.
    19 |   const state = useVerticalSizeState()
    20 |
  > 21 |   const aspectRatio = computed(() => state.value.aspectRatio)
       |                                            ^^^^^
    22 |   const width = computed(() =>
    23 |     Math.min(windowWidth.value, windowHeight.value * aspectRatio.value),
    24 |   )

ERROR in utils/useVerticalSize.ts:27:11
TS2339: Property 'value' does not exist on type 'Omit<Ref<{ aspectRatio: number; }>, "value">'.
    25 |   const height = computed(() => windowHeight.value)
    26 |   const setAspectRatio = (aspectRatio: Ref<number>) => {
  > 27 |     state.value.aspectRatio = aspectRatio.value
       |           ^^^^^
    28 |   }
    29 |
    30 |   return {

obviously the problem lies in my editor’s inability to correctly interpret RemoveableRef but I don’t want to overwrite the definition to solve the problem

19 |  const state = useVerticalSizeState()

I need a hint…this is my tsconfig.json

{
  "extends": "@tsconfig/node12/tsconfig.json",
  "compilerOptions": {
    "target": "es2018",
    "module": "esnext",
    "lib": ["ESNext", "DOM", "DOM.Iterable"],
    "moduleResolution": "node",
    "esModuleInterop": true,
    "strict": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "declaration": true,
    "declarationDir": "./types",
    "resolveJsonModule": true,
    "rootDir": ".",
    "baseUrl": ".",
    "paths": {
      "~/*": ["./*"],
      "@/*": ["./*"]
    },
    "types": [
      "@types/node",
      "@nuxt/types",
      "@nuxtjs/axios",
      "@nuxtjs/auth-next",
      "@nuxtjs/dayjs",
      "nuxt-i18n",
      "vuetify",
      "animejs"
    ],
    "typeRoots": ["./node_modules/@types", "./node_modules/vuetify/types"]
  },
  "exclude": ["node_modules", ".nuxt", "dist"]
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
antfucommented, Sep 22, 2021

What’s your TS version? Upgrade to v4.4 if possible

0reactions
khuyennguyen7007commented, Dec 2, 2021

Thank you very much for your suggestion @mao-shonen. Let me try upgrading to the nuxt bridge.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Property 'filter' does not exist on type object - Stack Overflow
I'm working with zustand and typescript. I got this error on my code. Property ...
Read more >
On static method Error TS2339: Property 'then' does not exist ...
On static method Error TS2339: Property 'then' does not exist on type '() => Promise' #10156.
Read more >
TypeScript errors and how to fix them
A list of common TypeScript errors and how to fix them.
Read more >
Typescript Type System: How Does it Really Work? Type ...
Let's have a look at the error message we get: Error:(54, 6) TS2339:Property 'name' does not exist on type '{}'. So what is ......
Read more >
useLocalStorage() react hook - usehooks-ts
Persist the state with local storage so that it remains after a page refresh. This can be useful for a dark theme. This...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found