Skip to content

Typescript definition not exporting properly #89

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
keego opened this issue Jul 3, 2018 · 5 comments
Closed

Typescript definition not exporting properly #89

keego opened this issue Jul 3, 2018 · 5 comments

Comments

@keego
Copy link
Contributor

keego commented Jul 3, 2018

The docs mention importing like so

import Vue from 'vue'
import VueRx from 'vue-rx'

Vue.use(VueRx)

However this yields a TypeScript error: TS1192: Module '...node_modules/vue-rx/types/index' has no default export

I was able to work around this via

import Vue from 'vue'
import * as VueRx from 'vue-rx'

const vueRx: any = VueRx
Vue.use(vueRx.default)

And things seem to be working normally now.

Here's the relevant package versions I'm using:

  "rxjs": "^6.2.1",
  "vue": "^2.5.2",
  "vue-router": "^3.0.1",
  "vue-rx": "^6.0.0"
@printjs

This comment has been minimized.

@kaorun343
Copy link

Hi.

Could you refer to this code?
https://github.com/vuejs/vue-rx/blob/master/types/test/index.ts

@keego
Copy link
Contributor Author

keego commented Jul 18, 2018

@kaorun343 You're referring to lines 2 and 6 right? Does that test case work?

When I import * as VueRx from 'vue-rx' and Vue.use(VueRx), VueRx still isn't used. As mentioned above, it only works if I Vue.use(VueRx.default). If you console.log('VueRx', { VueRx }) you'll see VueRx refers to a module with only a default export.

Exploring node_modules/vue-rx you can see the only export from vue-rx.esm.js is export default VueRx, so not sure why node_modules/vue-rx/types/index.d.ts says otherwise....

I've made a minimal repo to repro the issue here. I just updated to the latest @vue/cli and created the project with the following options:
screen shot 2018-07-18 at 11 37 35 am
I then ran

yarn add rxjs@^6.2.1
yarn add vue@^2.5.2
yarn add vue-router@^3.0.1
yarn add vue-rx@^6.0.0

and made a minimal component to demonstrate vue-rx usage

I also tested this out with a fresh JS Vue project with similar settings (just in case this was TS related) but I had the same problem.

Unless I've completely missed something, it seems like either (1) vue-rx.esm.js should be changed to export things differently, or (2) the vue-rx typings need to be updated. Personally, I prefer the (2) as the default export mechanics are simpler, cleaner, and more modern.

@yyx990803
Copy link
Member

Open to a PR that fixes the typings :)

@keego
Copy link
Contributor Author

keego commented Jul 23, 2018

@yyx990803 Well said :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants