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
I'm seeing some unexpected behavior in this minimal example:
typeConditionalKeys<Base,Condition>={// Map through all the keys of the given base type.[KeyinkeyofBase]-?:
// Pick only keys with types extending the given `Condition` type.Base[Key]extendsCondition// Retain this key since the condition passes.
? Key// Discard this key since the condition fails.
: never;// Convert the produced object into a union type of the keys which passed the conditional test.}[keyofBase];typeMyMap={a: {b: string;};c: {html: string;};d: never;};typeMyFilteredMap=ConditionalKeys<MyMap,{html: string}>;
The root cause is that never can extend anything. I'm not sure if this is expected behavior or not, but it was a gotcha for me. It can be fixed like so:
typeConditionalKeys<Base,Condition>={[KeyinkeyofBase]-?:
// The key is retained if its value extends the given `Condition` and is not `never`Base[Key]extendsCondition
? (Base[Key]extendsnever ? never : Key)
: never;}[keyofBase];
Upvote & Fund
We're using Polar.sh so you can upvote and help fund this issue.
The funding will be given to active contributors.
Thank you in advance for helping prioritize & fund our backlog.
The text was updated successfully, but these errors were encountered:
I'm seeing some unexpected behavior in this minimal example:
The root cause is that
never
can extend anything. I'm not sure if this is expected behavior or not, but it was a gotcha for me. It can be fixed like so:Upvote & Fund
The text was updated successfully, but these errors were encountered: