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.

docs: How to use other modules?

See original GitHub issue

How to use other modules?

// store/index.ts
import * as user from './user'

export const state = () => ({
  device: 'mobile'
})

export const getters = getterTree(state, {
  isMobile: (state) => state.device === 'mobile'
})

export const mutations = mutationTree(state, {
  setDevice(state, newValue: string) {
    state.device = newValue
  }
})

export const actions = actionTree(
  { state, getters, mutations },
  {
    async nuxtServerInit(vuexCxt, nuxtCxt: Context) {
      // Error: Argument of type '"user/info"' is not assignable to parameter of type 'never'.ts(2345)
      vuexCxt.commit('user/info', { name: 'xxx' })


      // Error: 'actions' implicitly has type 'any' because it does not have a type annotation
      // and is referenced directly or indirectly in its own initializer.ts(7022)
      // Error: 'accessorType' implicitly has type 'any' because it does not have a type annotation
      // and is referenced directly or indirectly in its own initializer.ts(7022)
      this.app.$accessor.user.info({ name: 'xxx' })
    }
  }
)

export const accessorType = getAccessorType({
  actions,
  getters,
  mutations,
  state,
  modules: { user }
})

// index.d.ts
import { accessorType } from '~/store'

declare module 'vue/types/vue' {
  interface Vue {
    $accessor: typeof accessorType
  }
}

declare module '@nuxt/types' {
  interface NuxtAppOptions {
    // If used: vuexCxt.commit('user/init')
    // Error: '$accessor' is referenced directly or indirectly in its own type annotation.ts(2502)
    $accessor: typeof accessorType
  }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

6reactions
danielroecommented, Dec 25, 2019

@NaClyxp My apologies for the delayed response.

Typescript 3.7 has brought some limitations on type inference. Specifically, there is now an issue with an accessor type used in the same module that exports it (thus, it only affects ~/store/index.ts).

So I would amend your code as follows:

export const accessorType = getAccessorType({
  // actions,
  getters,
  mutations,
  state,
    modules: { user }
  })

It’s not optimal, but unfortunately it seems to be required at the moment.

3reactions
tre-devcommented, Feb 4, 2020

Sorry, thought I’d answered already. That worked perfectly!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to upload Google Docs and files to modules in Canvas
Google Forms Tutorial · Linking Google Doc in Canvas (Assignment) · Google Docs - Share Your Document With Others - 2020 Update ·...
Read more >
6. Modules — Python 3.11.1 documentation
Such a file is called a module; definitions from a module can be imported into other modules or into the main module (the...
Read more >
Share and collaborate in My Drive - Google Support
Find the file or folder in Google Drive, Google Docs, Google Sheets, or Google Slides. · Open or select the file or folder....
Read more >
JavaScript modules - MDN Web Docs
The first thing you do to get access to module features is export them. This is done using the export statement. ... You...
Read more >
Documentation - Modules - TypeScript
How modules work in TypeScript. ... Modules import one another using a module loader. At runtime the module loader is responsible for locating...
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