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
typeUnwrapRef<T>=TextendsRef<infer V>
? UnwrapRef<V>// <-- this line will throw error
: TextendsArray<infer V>
? Array<UnwrapRef<V>>
: TextendsBailTypes
? T// bail out on types that shouldn't be unwrapped
: Textendsobject ? {[KinkeyofT]: UnwrapRef<T[K]>} : T
This is expected behavior. Conditional type alone doesn't guarantee recursive type alias. Type alias must have one layer of indirection, e.g., as field of interface, array/tuple's item type, as listed in #33050 .
In this example, UnwrapRef directly uses itself in the true branch of conditional type. This fails to meet the "indirection" requirement of recursive type alias.
Allowing recursion in conditional type is proposed in #26980 .
Though, I think the error reported here should be "cyclic type alias" rather than "type is not generic".
TypeScript Version: 3.7.0-dev.20191018
Search Terms:
Code
Example:
Expected behavior:
they are the same effects, but why couldn't I code like the first example?
Actual behavior:
Error:(14, 5) TS2315: Type 'UnwrapRef' is not generic.
Playground Link:
https://gist.github.com/Himself65/dea93908f17d25093938fcedc68eabd3
The text was updated successfully, but these errors were encountered: