-
-
Notifications
You must be signed in to change notification settings - Fork 569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SharedUnionFields
: Simplify implementation
#1000
SharedUnionFields
: Simplify implementation
#1000
Conversation
@Emiyaaaaa, IMO we should skip non-recursive types even if they are mixed with recursive ones, as suggested here. For eg., And, here's a possible implementation for the same: type SharedUnionFields<Union> =
Exclude<Union, NonRecursiveType | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown> | UnknownArray> extends infer ProcessableMembers
?
| Exclude<Union, ProcessableMembers>
| (IsNever<ProcessableMembers> extends true ? never : Simplify<Pick<ProcessableMembers, keyof ProcessableMembers>>)
: never; WDYT? |
I think this is better |
@Emiyaaaaa I've updated the PR, please have a look. I had to tweak the solution a bit from my earlier proposal to ensure it returns |
SharedUnionFields
implementationSharedUnionFields
: Simplify implementation
Simplifies the implementation of
SharedUnionFields
type, as mentioned here.ShareUnionFields
is essentially justPick
with an extra conditional for non-recursive types.Also, adds test cases to cover the non-recursive check, as mentioned here.