Skip to content
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

Use with nuxt typescript #178

Open
zecka opened this issue Aug 24, 2020 · 1 comment
Open

Use with nuxt typescript #178

zecka opened this issue Aug 24, 2020 · 1 comment

Comments

@zecka
Copy link

zecka commented Aug 24, 2020

Any way to use it with typescript ?

Currently i have following error:
Module '"../../../../node_modules/v-stripe-elements/types"' has no exported member 'VStripeCard'

I try also to import like that:

import { VStripeCard } from 'v-stripe-elements/lib/index'

And then add declare module 'v-stripe-elements/lib/index' in a .d.ts file

But then I have following error:
Cannot use import statement outside a module

@zecka zecka changed the title Use with typescript Use with nuxt typescript Aug 24, 2020
@zecka
Copy link
Author

zecka commented Aug 24, 2020

Okay, I get it, there may be a better way but I solve it as follows:

Create a plugin /plugins/v-stripe-elements.ts

In this file add following content

import Vue from 'vue'
import { VStripeCard } from 'v-stripe-elements/lib/index'
Vue.component('VStripeCard', VStripeCard)

then import it from nuxt.config.js (like you say #1 )

// nuxt.config.js
module.exports = {
  // ... your other config options ...
  plugins: [
    // ... other plugins you might have registered ... //
    { src: '~/plugins/v-stripe-elements', ssr: false }
  ]
}

Declare module v-stripe-element.d.ts

Create file v-stripe-element.d.ts inside type folder with following content:

declare module 'v-stripe-elements/lib/index'

Include v-stripe-element.d.ts in tsconfig if you are not already import all .d.ts

// tsconfig.json
{
    "compilerOptions":{
        "types": [ "./types/v-stripe-element.d.ts"]
    }
}

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

No branches or pull requests

1 participant