#Vue giving me problems with a type map

26 messages · Page 1 of 1 (latest)

twilit mountainBOT
#
plainblackguy#8238

Preview:ts ... result: Partial<ModelMap[T]["select"]> ) { this.props = result as UnwrapRef< Partial<ModelMap[T]["select"]> > // <-- this is the problem }, ...

fast flicker
#

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.

spare brook
#

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.

fast flicker
#

So would you say that this is a bug in pinia, or am I using pinia wrong?

spare brook
#

I'm not familiar with pinia so I can't say for sure, but I would guess a bug in pinia.

fast flicker
#

thanks

#

any ideas on how i could work around this?

#

ok, pinia is saying it's a vue problem that has already been reported

spare brook
#

Did they give an issue link?

fast flicker
#

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).

spare brook
#

I'd probably just ```ts
// @ts-expect-error vue#7278
this.props = result

#

Is it this issue a lot, or lots of other issues?

fast flicker
#

lots of issues related to generics. not specifically this issue with vue

spare brook
#

I don't think that is the right issue

fast flicker
#

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