partizan,

#vuejs #typescript

I'm trying to use generic type with vue composition API, and getting an error.

import { ref } from "vue";

function useContext<T extends BaseContext>(v: T) {  
 const context = ref<T | null>(null)  
 context.value = v  
 return {context}  
}

interface BaseContext {}  
src/main.ts:5:3 - error TS2322: Type 'T' is not assignable to type 'UnwrapRef<T> | null'.  

Is this a bug, or am i doing something wrong?

  • All
  • Subscribed
  • Moderated
  • Favorites
  • vuejs
  • DreamBathrooms
  • everett
  • InstantRegret
  • magazineikmin
  • thenastyranch
  • rosin
  • Durango
  • ethstaker
  • Youngstown
  • slotface
  • khanakhh
  • kavyap
  • ngwrru68w68
  • osvaldo12
  • JUstTest
  • tacticalgear
  • cubers
  • cisconetworking
  • anitta
  • provamag3
  • modclub
  • mdbf
  • GTA5RPClips
  • tester
  • megavids
  • normalnudes
  • Leos
  • lostlight
  • All magazines