mazipan / nuxt-storage

🛢 Utilities for easy read and write browser's storage in Nuxt.js project
MIT License
126 stars 8 forks source link

Any @types support planned? #237

Open Neosoulink opened 8 months ago

Neosoulink commented 8 months ago

Currently, I'm working on a Nuxt3 app and wanted to implement a small feature that will use localStorage...

My app is in typescript, and unfortunately, I wasn't able to load types: See the error:

Could not find a declaration file for module 'nuxt-storage/local-storage'. '/node_modules/nuxt-storage/local-storage/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/nuxt-storage` if it exists or add a new declaration (.d.ts) file containing `declare module 'nuxt-storage/local-storage';`ts(7016)

Even though the project (Nuxt-storage) was coded in typescript, the built files don't come with typescript support 🐧

julisch94 commented 2 months ago

I too was a bit annoyed from the TypeScript warnings, so I've added these declarations to a index.d.ts file in my project's root:

declare module 'nuxt-storage/local-storage' {
  export function getData(key: string)
  export function setData(key: string, value: string)
}

I'm only using those two functions so that's all I need. For sure there is a better way to do it this but I was lazy and want it to just work. 😄