GithubHelp home page GithubHelp logo

Comments (6)

microcipcip avatar microcipcip commented on August 16, 2024 1

You can also define it globally here.

declare module "vue/types/vue" {
  import { NuxtCookies } from 'cookie-universal-nuxt'

  interface Vue {
    $cookiez: NuxtCookies;
  }
}

declare module 'vuex/types/index' {
  import { NuxtCookies } from 'cookie-universal-nuxt'

  interface Store<S> {
    $cookiez: NuxtCookies
  }
}

from cookie-universal.

microcipcip avatar microcipcip commented on August 16, 2024

Sorry @xinbenlv I have no idea how to make this work. I am afraid that for now you'll have to avoid using the alias with Typescript. If there is anybody that knows how to fix this, I'll gladly accept a PR.

from cookie-universal.

xinbenlv avatar xinbenlv commented on August 16, 2024

Like-wise, I think the authors of vue.d.ts might know better.

I found some references might work

// file: https://github.com/microcipcip/cookie-universal/blob/1443a3d12325fb58fc9c62e3781b4e4adae206f3/packages/cookie-universal-nuxt/types/vue.d.ts#L8

shall reflect

// file: https://github.com/microcipcip/cookie-universal/blob/48486402fe1b23e3ea2ef315df3363600ff273a1/packages/cookie-universal-nuxt/lib/templates/cookie-universal-nuxt.js
import cookieUniversal from 'cookie-universal'

export default ({ req, res }, inject) => {
  const options = <%= JSON.stringify(options, null, 2) %>
  inject(options.alias, cookieUniversal(req, res, options.parseJSON))
}

Adding the author @Hiswe and @darthf1 for their wisdom.

Look forward to your comments, and if you could get to it that will be great, if not, I might go ahead and try a PR too, but I'd first trust and rely on your expertise

from cookie-universal.

microcipcip avatar microcipcip commented on August 16, 2024

Thanks a lot for investigating this. I think that because Typescript is statically analized the alias functionality cannot be implemented unless we accept any key as if it were a NuxtCookies. For instance, this may work but would be quite bad:

interface Vue {
   [key: string]: NuxtCookies;
}

I think another quick fix that could actually work would be defining the NuxtCookies interface declaration manually.

However, if you manage to, I will be very happy to accept your PR.

from cookie-universal.

xinbenlv avatar xinbenlv commented on August 16, 2024

A quick fix I did, more of a hack, is to declare the alias within the Single-File Component

    import {Component, Prop, Vue} from 'vue-property-decorator';

    @Component
    export default class SomeComponent extends Vue {
       //...   
       $cookiez: NuxtCookies;
       //...
    }

See this file: https://github.com/google/wikiloop-battlefield/blob/0c89ad365742ce6fe803fb48178ec5c8f1771a8d/components/ActionPanel.vue#L65

And it works.

And this bug is to look for more long term solution.

from cookie-universal.

stale avatar stale commented on August 16, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

from cookie-universal.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.