You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// TypesexportinterfaceRef<T=any>{value: UnwrapRef<T>}exportfunctionref<T>(raw: T): Ref<T>{returnnullasany;}typeBailTypes=|Function|Map<any,any>|Set<any>|WeakMap<any,any>|WeakSet<any>exporttypeUnwrapRef<T>={ref: TextendsRef<infer V> ? UnwrapRef<V> : Tarray: TextendsArray<infer V> ? Array<UnwrapRef<V>> : Tobject: {[KinkeyofT]: UnwrapRef<T[K]>}stop: T}[TextendsRef
? 'ref'
: TextendsArray<any>
? 'array'
: TextendsBailTypes
? 'stop'// bail out on types that shouldn't be unwrapped
: Textendsobject ? 'object' : 'stop']// /typestypeSupa={xx: number,x1: number}functionsetup(d: Supa,fn: ()=>Supa){constr=ref(d);// assigning the valuer.value=fn();// works as expected}functionsetup2<T>(d: T,fn: ()=>T){constr=ref(d)r.value=fn();// ERROR}
with simpler recursion
exportinterfaceRef<T=any>{value: UnwrapRef<T>}exporttypeUnwrapRef<T>=TextendsRef<infer V>
? UnwrapRefProp<V>
: UnwrapRefProp<T>exporttypeUnwrapRefProp<T>={[KinkeyofT]: UnwrapRefPropValue<T[K]>}typeBailTypes=|Function|Map<any,any>|Set<any>|WeakMap<any,any>|WeakSet<any>// NOTE not fully testedexporttypeUnwrapRefPropValue<T>=TextendsBailTypes
? T
: TextendsArray<infer V>
? UnwrapRef<V>[]
: TextendsRef<infer VR> ? UnwrapRef<VR> : UnwrapRef<T>// we might need to return T at some pointexportfunctionref<T>(raw: T): Ref<T>{returnnullasany;}typeSupa={xx: number,x1: number}functionsetup(d: Supa,fn: ()=>Supa){constr=ref(d);r.value=fn();// works as expected}functionsetup2<T>(d: T,fn: ()=>T){constr=ref(d)r.value=fn();// error `Type 'T' is not assignable to type 'UnwrapRef<T>'`}
Expected behavior:
Both should be assignable to value, the generic should be able to infer the type.
Actual behavior:
When using inside of generics it doesn't work, on the first example show an huge error log, the second one is error "Type 'T' is not assignable to type 'UnwrapRef<T>'"
I'm reading the definition of UnwrapRef<T> and can't convince myself that an arbitrary T should be assignable to it. Things that are true at zero-order might not be true at higher-order and TypeScript doesn't have the necessary higher-order logic to prove that all Ts going in to UnwrapRef eventually produce something assignable from another T.
TypeScript Version: 3.7.0-dev.20191009
Search Terms:
Code
with simpler recursion
Expected behavior:
Both should be assignable to value, the generic should be able to infer the type.
Actual behavior:
When using inside of generics it doesn't work, on the first example show an huge error log, the second one is
error "Type 'T' is not assignable to type 'UnwrapRef<T>'"
Playground Link:
example1
example2
The first example the code comes from vue-next
The text was updated successfully, but these errors were encountered: