In the advanced/intermediate challenge. It states that 'Bobby Tables' cannot have peanuts but to me, the solution seems to do the opposite and actually keep all the candies where there are peanuts 🤔
type HasPeanuts<A> = A extends { peanuts: true } ? A : never;
type AllCandiesWithoutPeanuts = HasPeanuts<AllCandies>
My bad, should have said something instead of just plopping down a solution - yes you are correct saying that:
type AllCandiesWithoutPeanuts = HasPeanuts<AllCandies>
is the opposite of the solution. Something more correct would have the inverted type. I'm not sure how one would go from HasPeanuts to something like OmitsPeanuts but declaring it from scratch is straightforward:
type OmitsPeanuts<A> = A extends { peanuts: true } ? never : A;
In the advanced/intermediate challenge. It states that
'Bobby Tables' cannot have peanuts
but to me, the solution seems to do the opposite and actually keep all the candies where there are peanuts 🤔I agree with your implementation. I was discussing the solution provided in this post :)
Maybe @gcrev93 can help me if I misinterpreted it
My bad, should have said something instead of just plopping down a solution - yes you are correct saying that:
is the opposite of the solution. Something more correct would have the inverted type. I'm not sure how one would go from
HasPeanuts
to something likeOmitsPeanuts
but declaring it from scratch is straightforward:Bobby is on his way to the hospital now. Thankfully somebody had an epi-pen ready.
Also, the proposed solution for AllCandies removes all candies from the union, instead of only keeping the candies.
This should probably use
Extract
instead ofExclude
: