Preview:ts ... result: Partial<ModelMap[T]["select"]> ) { this.props = result as UnwrapRef< Partial<ModelMap[T]["select"]> > // <-- this is the problem }, ...
#Vue giving me problems with a type map
26 messages · Page 1 of 1 (latest)
For some reason Vue/Pinia is adding UnwrapRef<> to my types types, which forces me to add the assertion all over the place with the extra UnwrapRef<> wrapped around my actual types
this only happens when I'm using generics
If i were to fill in the T with 'User' or 'APIKey' everywhere then it works without doing this UnwrapRef
Please note that this code doesn't make a lot of sense as presented, it's cut down to this very abbreviated version from about 1000 lines
Any guidance on how to solve this would be much appreciated
@stark quartz @spare brook @maiden heath this is the problem we were discussing last night. At your recommendation I've made a minimal reproduction.
It looks like pinia is to blame. The type of this in setState is wrong. It you turn off noImplicitThis in the ts config options, the error goes away, but of course you lose type safety ie this.props = 1 also compiles.
So would you say that this is a bug in pinia, or am I using pinia wrong?
I'm not familiar with pinia so I can't say for sure, but I would guess a bug in pinia.
thanks
any ideas on how i could work around this?
cuz obviously even if it is a pinia bug, which i have now reported (https://github.com/vuejs/pinia/issues/2122 ) it will be some time before they could fix it
ok, pinia is saying it's a vue problem that has already been reported
Did they give an issue link?
no, but i think it's this: https://github.com/vuejs/core/issues/7278
GitHub
Vue version 3.2.45 Link to minimal reproduction https://stackblitz.com/edit/vitejs-vite-eoqyep?file=src/composables/useFilter.ts Steps to reproduce The TS error presents itself inside the useFilter...
although there are a few others it could be as well
i keep running into issues like this with typescript because i'm using lots of generics (necessarily for the project i'm working on).
I'd probably just ```ts
// @ts-expect-error vue#7278
this.props = result
Is it this issue a lot, or lots of other issues?
lots of issues related to generics. not specifically this issue with vue
I don't think that is the right issue
i'm building a web services framework for a specific project that has to wrap database tables that i don't know the properties of in advance
and thus i need to use lots of generics to handle all the things that the end users will throw at me
but i've now filed several bugs with typescript, vue, drizzle (the ORM), and a few other odds and ends, cuz i keep running into what appear to be corner cases with me pushing the edges of typescript
it makes me wonder if i'm trying to do stuff that typescript just isn't supposed to do