mirror of
https://github.com/sindresorhus/type-fest.git
synced 2026-02-01 15:59:43 +00:00
OmitDeep: Fix removal of multiple paths within arrays (#1049)
This commit is contained in:
parent
9aba4c33c8
commit
fa6e31b70f
16
source/omit-deep.d.ts
vendored
16
source/omit-deep.d.ts
vendored
@ -1,10 +1,10 @@
|
||||
import type {UnionToTuple} from 'expect-type';
|
||||
import type {ArraySplice} from './array-splice';
|
||||
import type {ExactKey, IsArrayReadonly, NonRecursiveType, SetArrayAccess, ToString} from './internal';
|
||||
import type {IsEqual} from './is-equal';
|
||||
import type {IsNever} from './is-never';
|
||||
import type {LiteralUnion} from './literal-union';
|
||||
import type {Paths} from './paths';
|
||||
import type {SharedUnionFieldsDeep} from './shared-union-fields-deep';
|
||||
import type {SimplifyDeep} from './simplify-deep';
|
||||
import type {UnknownArray} from './unknown-array';
|
||||
|
||||
@ -92,11 +92,19 @@ type AddressInfo = OmitDeep<Info1, 'address.1.foo'>;
|
||||
*/
|
||||
export type OmitDeep<T, PathUnion extends LiteralUnion<Paths<T>, string>> =
|
||||
SimplifyDeep<
|
||||
SharedUnionFieldsDeep<
|
||||
{[P in PathUnion]: OmitDeepWithOnePath<T, P>}[PathUnion]
|
||||
>,
|
||||
OmitDeepHelper<T, UnionToTuple<PathUnion>>,
|
||||
UnknownArray>;
|
||||
|
||||
/**
|
||||
Internal helper for {@link OmitDeep}.
|
||||
|
||||
Recursively transforms `T` by applying {@link OmitDeepWithOnePath} for each path in `PathTuple`.
|
||||
*/
|
||||
type OmitDeepHelper<T, PathTuple extends UnknownArray> =
|
||||
PathTuple extends [infer Path, ...infer RestPaths]
|
||||
? OmitDeepHelper<OmitDeepWithOnePath<T, Path & (string | number)>, RestPaths>
|
||||
: T;
|
||||
|
||||
/**
|
||||
Omit one path from the given object/array.
|
||||
*/
|
||||
|
||||
@ -135,3 +135,9 @@ expectType<{array: [
|
||||
|
||||
declare const tuple: OmitDeep<{array: BaseType['tuples']}, 'array.0'>;
|
||||
expectType<{array: [unknown, 'bar']}>(tuple);
|
||||
|
||||
declare const arrayWithMultiplePaths: OmitDeep<{array: Array<{a: string; b: number; c: string}>}, `array.${number}.a` | `array.${number}.b`>;
|
||||
expectType<{array: Array<{c: string}>}>(arrayWithMultiplePaths);
|
||||
|
||||
declare const tupleWithMultiplePaths: OmitDeep<{tuple: [{a: string; b: number; c: string}]}, 'tuple.0.a' | 'tuple.0.b'>;
|
||||
expectType<{tuple: [{c: string}]}>(tupleWithMultiplePaths);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user