TreasureTrails/node_modules/remeda/dist/omit.cjs.map

1 line
6.9 KiB
Text
Raw Permalink Normal View History

2026-03-18 09:02:21 -05:00
{"version":3,"file":"omit.cjs","names":["purry","hasAtLeast"],"sources":["../src/omit.ts"],"sourcesContent":["import type { EmptyObject, IsNever, KeysOfUnion } from \"type-fest\";\nimport { hasAtLeast } from \"./hasAtLeast\";\nimport type { IsBounded } from \"./internal/types/IsBounded\";\nimport type { IsBoundedRecord } from \"./internal/types/IsBoundedRecord\";\nimport type { PartitionByUnion } from \"./internal/types/PartitionByUnion\";\nimport type { SimplifiedWritable } from \"./internal/types/SimplifiedWritable\";\nimport type { TupleParts } from \"./internal/types/TupleParts\";\nimport { purry } from \"./purry\";\n\ntype OmitFromArray<T, Keys extends readonly PropertyKey[]> =\n // Distribute unions for both object types and key arrays.\n T extends unknown\n ? Keys extends unknown\n ? // The output is always writable because we always create a new object!\n SimplifiedWritable<\n IsNever<Extract<Keys[number], keyof T>> extends true\n ? // When none of the keys belong to T we can short-circuit and\n // simply return T as-is because `omit` would do nothing.\n T\n : IsBoundedRecord<T> extends true\n ? OmitBounded<T, Keys>\n : OmitUnbounded<T, Keys>\n >\n : never\n : never;\n\ntype OmitBounded<T, Keys extends readonly PropertyKey[]> =\n // We build our output by first considering any key present in the keys array\n // as being omitted. This object would contain all keys that are unaffected at\n // all by this omit operation.\n FixEmpty<Omit<T, Keys[number]>> &\n // But we might be missing keys that are optional in the keys tuple (and\n // thus might not be removed). Because these keys are optional, their props\n // in the output also need to be optional.\n Partial<\n Pick<\n T,\n Exclude<\n // Find all keys that can either be omitted or not, these are all keys\n // in unions in the required parts of the keys tuple (the prefix and\n // the suffix), as well as all keys in the optional parts and the rest\n // item.\n | PartitionByUnion<TupleParts<Keys>[\"required\"]>[\"union\"]\n | TupleParts<Keys>[\"optional\"][number]\n | TupleParts<Keys>[\"item\"]\n | PartitionByUnion<TupleParts<Keys>[\"suffix\"]>[\"union\"],\n // We then need to remove from these any items which *also* are\n // ensured to always exist in the keys tuple, these are the elements\n // of the required parts of the tuple which are singular (not unions).\n | PartitionByUnion<TupleParts<Keys>[\"required\"]>[\"singular\"]\n | PartitionByUnion<TupleParts<Keys>[\"suffix\"]>[\"singular\"]\n >\n >\n >;\n\n/**\n * The built-in `Omit` type doesn't handle unbounded records correctly! When\n * omitting an unbounded key the result should be untouched as we can't tell\n * what got removed, and can't represent an object that had \"something\" removed\n * from it, but instead it returns `{}`(?!) The same thing applies when a key\n * is only optionally omitted for the same reasons. This is why we don't use\n * `Omit` at all for the unbounded case.\n *\n * @see https://www.typescriptlang.org/play/?#code/C4TwDgpgBAqgdgIwPYFc4BMLqgXigeQFsBLYAHgCUIBjJAJ3TIGdg7i4BzAGigCIALCABshSXgD4eLNp3EBuAFAB6JVDUA9APxA\n */\ntype OmitUnbounded<T, Keys extends readonly PropertyKey[]> = T &\n // Any key we know for sure is being omitted needs to become \"impossible\" to\n // access; for an unbounded record this means merging it with a bounded record\n // with `never` value for these keys.\n Record<\n Bounded<\n | PartitionByUnion<TupleParts<Keys>[\"required\"]>[\"singular\"]\n | PartitionByUnion<TupleParts<Keys>[\"suffix\"]>[\"singular\"]\n >,\n never\n >;\n\n/**\n * When `Omit` omits **all** keys from a bounded record it results in `{}` which\n * doesn't match what we'd expect to be returned in terms of a useful type as\n * the output of `Omit`.\n */\ntype FixEmpty<T> = IsNever<keyof T> exten