joonhocho / tsdef

TypeScript common pattern shortcut definitions / utility gist library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DeepExclude

brentjanderson opened this issue · comments

I've tried this but it doesn't quite get me where I want to go:

type DeepExclude<T, U> = {
  [P in Exclude<keyof T, U>]: T[P] extends Array<infer I> ? Array<DeepExclude<I, U>> : DeepExclude<T[P], U>;
};

Curious if this is something easily solvable in TypeScript? I have a different implementation, but it's a mess consisting of about 30 conditional checks that's use-case specific. I think a DeepExclude would be a better utility, and meet my specific use-case pretty well. Thoughts?

https://stackoverflow.com/a/64900252/214950 works pretty well for me. Can you take it for a spin?