docs: How to use other modules?
See original GitHub issueHow 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:
- Created 4 years ago
- Reactions:7
- Comments:15 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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:
It’s not optimal, but unfortunately it seems to be required at the moment.
Sorry, thought I’d answered already. That worked perfectly!