Skip to content

Error while using store with nativescript-vue typescript #462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
azs06 opened this issue Mar 21, 2019 · 4 comments
Closed

Error while using store with nativescript-vue typescript #462

azs06 opened this issue Mar 21, 2019 · 4 comments

Comments

@azs06
Copy link

azs06 commented Mar 21, 2019

Version

2.0.0

Reproduction link

https://github.com/azs06/test-ns-app

Platform and OS info

Mac OS 10.14.3/Android 8.0.0/Nativescript Vue 2.0.0

Steps to reproduce

tns preview --bundle

What is expected?

Adding a Vuex store should just work without any issue. For example, I added this store

import Vue from 'nativescript-vue'
import Vuex from 'vuex';


Vue.use(Vuex)

const debug = process.env.NODE_ENV !== 'production'

const store = new Vuex.Store({
    strict: debug
})

export default store

And added it to the Vue instance

new Vue({
  store,		
  render: h => h('frame', [h(App)])
}).$start();

What is actually happening?

Getting this error on console

TS2345: Argument of type '{ store: any; render(h: CreateElement): VNode; }' is not assignable to parameter of type 'ComponentOptions<NativeScriptVue<View>, DefaultData<NativeScriptVue<View>>, DefaultMethods<NativeScriptVue<View>>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<...>>'.
  Object literal may only specify known properties, and 'store' does not exist in type 'ComponentOptions<NativeScriptVue<View>, DefaultData<NativeScriptVue<View>>, DefaultMethods<NativeScriptVue<View>>, DefaultComputed, PropsDefinition<Record<string, any>>, Record<...>>'.

Also vscode inidicating this error.


App preview works properly even with the error. Provided a GitHub link of a freshly installed project

@acidbiscuit
Copy link
Contributor

Type definitions that extend ComponentOptions and VueConstructor are declared inside vuex module. Since in reproduction project store is imported as *.js file, type definitions for vuex are not picked up.

Changing store.js to store.ts and corresponding import inside main.ts will fix the issue.

Side note: take a look nativescript-dev-typescript package which plugs in TypeScript into NativeScript project (uninstalling package-lock.json, platforms, node_modules, and hooks will be required, same as for most NativeScript plugins).

@azs06
Copy link
Author

azs06 commented Mar 27, 2019

@acidbiscuit Thanks, changing store.js to store.ts did solve the issue. Though there was another error, to solve that I had to install @types/node.

@msaelices
Copy link

I've just improved the Vuex support when generating new apps using the vue-cli-template: nativescript-vue/vue-cli-template#124 After this change, the vue init nativescript-vue/vue-cli-template will create a ready for use app with an empty Vuex store.

I think BTW this issue is solved so I will close it. Please re-open it if I missed something.

@nativescript-vue-bot
Copy link
Collaborator

We are locking this issue because it has been closed for more than 14 days.

If the issue comes up again please open a new issue with additional details.

@nativescript-vue nativescript-vue locked as resolved and limited conversation to collaborators Apr 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

4 participants