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

1 line
9 KiB
Text
Raw Normal View History

2026-03-18 09:02:21 -05:00
{"version":3,"file":"pickBy.cjs","names":["purry","out: Partial<Record<string, unknown>>"],"sources":["../src/pickBy.ts"],"sourcesContent":["import type { IsNever, Simplify } from \"type-fest\";\nimport type { EnumerableStringKeyOf } from \"./internal/types/EnumerableStringKeyOf\";\nimport type { EnumerableStringKeyedValueOf } from \"./internal/types/EnumerableStringKeyedValueOf\";\nimport type { IsBoundedRecord } from \"./internal/types/IsBoundedRecord\";\nimport type { ToString } from \"./internal/types/ToString\";\nimport { purry } from \"./purry\";\n\n// When the predicate isn't a type-guard we don't know which properties would be\n// part of the output and which wouldn't so we can only safely downgrade the\n// whole object to a Partial of the input.\ntype EnumeratedPartial<T> = T extends unknown\n ? Simplify<\n IsBoundedRecord<T> extends true\n ? {\n // Object.entries returns keys as strings.\n -readonly [P in keyof T as ToString<P>]?: Required<T>[P];\n }\n : // For unbounded records (a simple Record with primitive `string` or\n // `number` keys) the return type here could technically be T; but for\n // cases where the record is unbounded but is more complex (like\n // `symbol` keys) we want to \"reconstruct\" the record from just its\n // enumerable components (which are the ones accessible via\n // `Object.entries`).\n Record<EnumerableStringKeyOf<T>, EnumerableStringKeyedValueOf<T>>\n >\n : never;\n\n// When the predicate is a type-guard we have more information to work with when\n// constructing the type of the output object. We can safely remove any property\n// which value would never come up true for the predicate, AND we can also\n// assume that properties that match the predicate perfectly would **always**\n// show up in the output object. Hence to build the output object we need to\n// build and merge 2 output objects: One for the properties which have a value\n// of at type that would always yield a `true` result from the predicate, these\n// are the \"matches\", which would not change the \"optionality\" of the input\n// object's props, and one for partial matches which would also make the props\n// optional (as they could have a value that would be filtered out).\ntype EnumeratedPartialNarrowed<T, S> = T extends unknown\n ? Simplify<\n IsBoundedRecord<T> extends true\n ? ExactProps<T, S> & PartialProps<T, S>\n : // For unbounded records we need to \"reconstruct\" the record and\n // narrow the value types. Similar to the non-narrowed case, we need\n // to also ignore `symbol` keys and any values that are only relevant\n // to them.\n Record<\n EnumerableStringKeyOf<T>,\n Extract<EnumerableStringKeyedValueOf<T>, S>\n >\n >\n : never;\n\n// The exact case, props here would always be part of the output object\ntype ExactProps<T, S> = {\n // Object.entries returns keys as strings.\n -readonly [P in keyof T as ToString<\n IsExactProp<T, P, S> extends true ? P : never\n >]: Extract<Required<T>[P], S>;\n};\n\n// The partial case, props here might be part of the output object, but might\n// not be, hence they are optional.\ntype PartialProps<T, S> = {\n // Object.entries returns keys as strings.\n -readonly [P in keyof T as ToString<\n IsPartialProp<T, P, S> extends true ? P : never\n >]?: IsNever<Extract<T[P], S>> extends true\n ? // If the result of extracting S from T[P] is never but S still extends\n // it, it means that T[P] is too wide and S can't be extracted from it:\n // e.g. if T[P] is `number` S is `1` then `Extract<number, 1> === never`.\n // For these cases we can return S directly as the type as it's already\n // very narrowed compared to T[P].\n S extends T[P]\n ? S\n : never\n : Extract<T[P], S>;\n};\n\n// If the input object's value type extends itself when the type-guard is\n// extracted from it we can safely assume that the predicate would alw