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
typeMainT='john'|'doe'typeValueT<TextendsMainT>=Textends'john' ? string : Textends'doe' ? number : nevertypeReturnT<TextendsMainT>=Textends'john' ? Uint32Array : Textends'doe' ? Uint8Array : neverfunctionisMainT<TextendsMainT>(value: unknown,mainType: T): value is T{returnvalue===mainType}functiontest<TextendsMainT>(key: T,value: ValueT<T>): ReturnT<T>{if(isMainT(key,'john')){constn=value.split('')// ValueT<T> is not inferred when T is known by using typeguard on `key`returnnewUint32Array()// ReturnT<T> is not inferred when T is known}}
π Actual behavior
When the type of the main generic type (MaintT) is identified by a User-Defined Type Guard function, the other conditional types based on this main type are not identified and TS keeps it generic.
π Expected behavior
ReturnT<T> and ValueT<T> became inferred after T has been identified
The text was updated successfully, but these errors were encountered:
Bug Report
π Search Terms
inferring, infer, generic type, generic, user-defined type guard, conditional type
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
When the type of the main generic type (
MaintT
) is identified by a User-Defined Type Guard function, the other conditional types based on this main type are not identified and TS keeps it generic.π Expected behavior
ReturnT<T>
andValueT<T>
became inferred after T has been identifiedThe text was updated successfully, but these errors were encountered: