Skip to content
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

OmitDeep: Fix removal of multiple paths within arrays #1049

Merged
merged 1 commit into from
Feb 9, 2025

Conversation

som-sm
Copy link
Collaborator

@som-sm som-sm commented Feb 7, 2025

Fixes #959 (comment)

Just enabling recurseIntoArrays for SharedUnionDeep within OmitDeep fixes the above issue, however, it causes some existing test cases to fail, as SharedUnionDeep currently fails when instantiated with arrays where the non-fixed part precedes the fixed part (will open an issue for this).

import { SharedUnionFieldsDeep } from "type-fest";

type Test = SharedUnionFieldsDeep<{a: [...{a: 1}[], {b: 1}]}, {recurseIntoArrays: true}>
//   ^? type Test = { a: {}[]; }

So, this PR removes usage of SharedUnionDeep from OmitDeep and replaces it with logic similar to what is used in SetRequiredDeep.

/**
Internal helper for {@link SetRequiredDeep}.
Recursively transforms the `BaseType` by applying {@link SetRequiredDeepSinglePath} for each path in `KeyPathsTuple`.
*/
type SetRequiredDeepHelper<BaseType, KeyPathsTuple extends UnknownArray> =
KeyPathsTuple extends [infer KeyPath, ...infer RestPaths]
? SetRequiredDeepHelper<SetRequiredDeepSinglePath<BaseType, KeyPath>, RestPaths>
: BaseType;

@som-sm som-sm requested a review from sindresorhus February 7, 2025 17:08
@sindresorhus sindresorhus merged commit fa6e31b into main Feb 9, 2025
12 checks passed
@sindresorhus sindresorhus deleted the fix/omit-deep-array-with-multiple-paths branch February 9, 2025 08:58
Repository owner deleted a comment from viceice Feb 16, 2025
Repository owner deleted a comment from viceice Feb 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OmitDeep for array item
2 participants