Comments (6)
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.
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.
Like-wise, I think the authors of vue.d.ts
might know better.
I found some references might work
- Blog post: Can I dynamically add properties to an interface in Typescript? and it's section
Dynamic keys
.
// 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.
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.
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.
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)
- Can't set cookie on mac os browser HOT 2
- Cookie get is not working after chanhing route in asynd fetch or asyncData HOT 4
- client
- `set` and `remove` a cookie don't work together HOT 8
- Property 'nodeCookie' does not exist on type 'NuxtCookies' HOT 7
- No cookies received from the server HOT 5
- warnings with nuxt3 HOT 2
- PATH not working HOT 2
- cookie.remove should not throw when the cookie is not found HOT 1
- removeAll typing is wrong HOT 1
- Get deleted cookies in duplicate tab
- Cookies disappear HOT 1
- o.set-cookie.map is not a function
- missing license information
- Add cookie-universal-nuxt to nuxt.config.ts HOT 12
- Support top-level options
- remove in middleware not work HOT 3
- remove cookies from client works inconsistency HOT 1
- ERROR Cannot set headers after they are sent to the client
- It can't remove token in server HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cookie-universal.