docs: fix unnarrowable type predicate in plan Task 5 pipeline

mapWithConcurrency's callback return was inferred as a union of two object
literal types rather than one type with deep: TDeep | undefined, so the
'entry is Pair' predicate was rejected: a type predicate's type must be
assignable to its parameter's type. Added an explicit EnrichedCandidate
annotation on the call. Tests passed but tsc did not, so this was only
visible via typecheck.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
Lucas Winther
2026-09-18 07:28:20 +02:00
co-authored by Claude Opus 5
parent 3d3b8ff512
commit 7b07241367
+26 -9
View File
@@ -1536,18 +1536,35 @@ export async function searchPipeline<TShallow, TDeep>(
}
// Phase 2: bounded enrichment.
//
// The explicit EnrichedCandidate annotation is required, not stylistic:
// without it TypeScript infers the callback's return as a UNION of two
// object literal types ({ deep: Awaited<TDeep> } | { deep: undefined })
// rather than a single type with `deep: TDeep | undefined`. The narrowing
// predicate below is then rejected, because a type predicate's type must be
// assignable to its parameter's type and `Pair` is not assignable to the
// `{ deep: undefined }` arm.
interface EnrichedCandidate {
candidate: TShallow;
deep: TDeep | undefined;
}
let enrichmentFailures = 0;
const enriched = await mapWithConcurrency(selected, concurrency, async (candidate) => {
try {
return { candidate, deep: await spec.enrich(candidate) };
} catch (error: unknown) {
if (isFatalSearchError(error)) {
throw error;
const enriched: EnrichedCandidate[] = await mapWithConcurrency<TShallow, EnrichedCandidate>(
selected,
concurrency,
async (candidate) => {
try {
return { candidate, deep: await spec.enrich(candidate) };
} catch (error: unknown) {
if (isFatalSearchError(error)) {
throw error;
}
enrichmentFailures++;
return { candidate, deep: undefined };
}
enrichmentFailures++;
return { candidate, deep: undefined };
}
});
);
interface Pair {
candidate: TShallow;