What is the correct data type for the vuex store that is passed to the vuex plugin when it is being initialized?

Here is how the store initialization process is currently being implemented:

/* Logic */
import Vue from 'vue'
import Vuex, { StoreOptions } from 'vuex'

Vue.use(Vuex)

const DataManager = new UserDataManager()

type RootStateType = {
  version: string
}

const store: StoreOptions<RootStateType> = {
  // @ts-ignore
  state: {
    version: '1.0.0'
  },
  modules: {...},
  plugins: [DataManager.init()]
}

export default new Vuex.Store<RootStateType>(store)

Now, let's talk about the plugin implementation:

export class UserDataManager {
  ... some logic here

  public init () {
    return (store: <TYPE?>) => {
      store.watch(
        (state: RootStateType) => {
          return [state.user.authentication.id]
        },
        (watched: string[]) => {
          const userID = watched[0]
          ... more logic
        }
      )
    }
  }
}

I'm facing a bit of confusion regarding passing the correct type in this scenario. I attempted to pass it using:

type storeType = StoreOptions<RootStateType>

...
    return (store: storeType) => {
...

However, this resulted in the following error message:

TS2339: Property 'watch' does not exist on type 'StoreOptions<RootStateType>'
I would greatly appreciate any insights or suggestions that could shed light on this issue :-)

Answer №1

After taking a glance at the vuex-persist repository, it seems that using Store<RootStateType> should be viable.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

using outlines for FontAwesome icons in React Native

I am struggling to use the fontAwesome + icon in the middle of a circle as one item. I have tried placing it inside a circle icon, but it doesn't seem to work properly. import IconFA from 'react-native-vector-icons/FontAwesome'; < ...

Trouble encountered while using useRef in TypeScript

I'm encountering an issue with the code below; App.tsx export default function App() { const [canvasRef, canvasWidth, canvasHeight] = useCanvas(); return ( <div> <canvas ref={canvasRef} /> </div> ) ...

When transferring the code to the src folder, tRPC encounters issues and stops functioning

Currently, I am working on developing a basic Twitter clone using Next and TRPC. While tRPC is up and running smoothly, I am looking to streamline my code by consolidating it all within the src directory. However, upon moving everything, I encountered an i ...

What could be causing the error I encounter when attempting to send JSON in a GET request?

Currently, I am utilizing Angular 10 in my project. I am attempting to send an object in a GET request, so I decided to convert it to JSON: getData(dataPlan: Data): Observable<Response<InfoType[]>> { return this.client.get<Response< ...

Issues with the messaging functionality of socket.io

Utilizing socket.io and socket.io-client, I have set up a chat system for users and operators. The connections are established successfully, but I am encountering strange behavior when it comes to sending messages. For instance, when I send a message from ...

Tips for resolving SyntaxError: Unable to utilize import when integrating Magic with NextJS in a Typescript configuration

Looking to integrate Magic into NextJS using TypeScript. Following a guide that uses JavaScript instead of TypeScript: https://github.com/magiclabs/example-nextjs Encountering an issue when trying to import Magic as shown below: import { Magic } from &qu ...

Utilize the express library (NodeJS, TypeScript) to send back the results of my function

I am curious about how I can handle the return values of my functions in my replies. In this specific scenario, I am interested in returning any validator errors in my response if they exist. Take a look at my SqlCompanyRepository.ts: async create(compan ...

Ways to retrieve data from an Observable and save it in an Array categorized by a specific identifier

The data I have is structured as follows: Location: lat: 43.252967 lng: 5.379856 __proto__: Object customerId: "5cd430c65304a21b9464a21a" id: "5d5a99c62a245117794f1276" siteId: "5d0ce7c4a06b07213a87a758" __proto__: Object 1: Location: {lat: 43.249466, lng ...

Rule in ESLint mandating return type for arrow functions

I currently have the following arrow function within my Angular project: this.httpClient.get('url').subscribe((response)=>{ }); It is important to note that ESLint should detect an error in the above code due to not specifying a return type. ...

Ways to create a method that can be overridden

Is there a way to declare a virtual method in TypeScript? I'm attempting to achieve something similar to the following: export abstract class SuperClass { public virtual enable(enableComponents: boolean): void { } } ...

Error encountered in Angular with Karma and Jasmine: The function this.Service.<foo> is not defined in the Lifecycle Hook

When running Karma and Jasmine tests using the npm run test -- --no-watch --no-progress command with Karma/Jasmine, an error is thrown: Chrome 92.0.4515.159 (Mac OS 10.15.7) LoginComponent should create FAILED TypeError: this.loggerService.onDebug is n ...

Upgrading from Angular 2 to 4 causes compilation failure in project

Recently, I upgraded my Angular project from version 2 to version 4. The steps I followed for this upgrade are as follows: 1- Deleted the /node_modules/ folder 2- Executed the following command: npm install @angular/common@latest @angular/compiler@lat ...

What factors contribute to TypeScript having varying generic function inference behaviors between arrow functions and regular functions?

Consider the TypeScript example below: function test<T = unknown>(options: { a: (c: T) => void, b: () => T }) {} test({ a: (c) => { c }, // c is number b: () => 123 }) test({ b: () => 123, a: (c) => { retur ...

`Angular Image Upload: A Comprehensive Guide`

I'm currently facing a challenge while attempting to upload an image using Angular to a Google storage bucket. Interestingly, everything works perfectly with Postman, but I've hit a roadblock with Angular Typescript. Does anyone have any suggesti ...

Using vuexfire's firestoreAction to bind with a specific argument is a powerful

I'm attempting to connect my module's store to a document import Vue from 'vue' import { db } from '../my-firebase/db' import { firestoreAction } from 'vuexfire' export const user = { ... actions: { ...

The functionality of CSS transitions may be affected when dynamically adding a class

Creating a custom CSS for my main div: .main { height: 0%; position: absolute; width: 100%; z-index: 100; background: whitesmoke; bottom: 0; border-radius: 15px; padding: 20px; color: gray; left: 0; right: 0; transition: height 1s e ...

Tips for updating state in React TypeScript 2.0?

Working with a small component built using React and TypeScript has presented a unique challenge. interface Props { } interface State { isOpen: boolean; } class App extends React.Component<Props, State> { constructor(props: Props) { super ...

Creating a setup with Angular 2+ coupled with Webpack and a Nodejs

I have successfully configured Angular2+webpack along with NodeJs for the backend. Here is a basic setup overview: webpack.config.js: var webpack = require('webpack') var HtmlWebpackPlugin = require('html-webpack-plugin') var Extract ...

Issue with Loosing Focus in React TextInput when typing the letter "S"

My TextInput is acting strangely - it loses focus only when I type the letter s. All other letters work fine. <FormControl key={"1"} sx={{ m: 1 }} variant="outlined" onChange={handleFilterValueChange}> <InputLabel htmlFor=& ...

I'm curious if anyone has experimented with implementing TypeScript enums within AngularJS HTML pages

During my Typescript project, I defined an enum like this: enum Action { None = 0, Registering = 1, Authenticating = 2 }; In the controller, I declared a property named action as follows: class AuthService implements IAuthService { action: number; ...