MetinSeylan / Vue-Socket.io

😻 Socket.io implementation for Vuejs and Vuex
https://metin.sh
MIT License
3.95k stars 496 forks source link

'options' does not exist in type 'VueSocketOptions',but it works #300

Open kkstun opened 3 years ago

kkstun commented 3 years ago

ERROR in E:/works-web/ws1/src/main.ts(21,3): 21:3 Argument of type '{ debug: true; connection: string; vuex: { store: Store<{}>; actionPrefix: string; mutationPre fix: string; }; options: { path: string; transports: string[]; }; }' is not assignable to parameter of type 'VueSocke tOptions'. Object literal may only specify known properties, and 'options' does not exist in type 'VueSocketOptions'. 19 | mutationPrefix: 'SOCKET_' 20 | },

21 | options: { path: '/tushu/', transports: ['websocket'] } // Optional options | ^ 22 | })) 23 | 24 | new Vue({ Version: typescript 3.9.7

`Vue.use(new VueSocketIO({ debug: true, connection: 'http://192.168.9.17:1234', vuex: { store, actionPrefix: 'SOCKET', mutationPrefix: 'SOCKET' }, options: { path: '/tushu/', transports: ['websocket'] } // Optional options }))

new Vue({ router, store, render: h => h(App) }).$mount('#app')`

it works!but why

lyutian commented 2 years ago

The npm package is not up to date. There's no options definition in VueSocketOptions, so, the type check will report error. Need these code in vue-socketio.js/index.d.ts: https://github.com/MetinSeylan/Vue-Socket.io/blob/61614c865e9b1479c313f2414f0eb23b957ed226/index.d.ts#L55-L57

    options?: {
        path?: string,
        transports?: Array<string>
    }