mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-01 07:33:12 +08:00
`new Map()` has no type arguments, and the no-argument constructor gives the checker nothing to infer them from: the expression types as Map<unknown, unknown> however the destination spells it. Construction adopted a contextual type only when it mapped to a map, so a nullable or readonly annotation — `Map<K, V> | undefined`, `Map<K, V> | null`, `ReadonlyMap<K, V> | undefined`, an optional record field — refused the very value its slot was built for (SC2003; pi's extension registry, whose `handlers?: Map<...>` fields start empty). A Map value can only inhabit a union's map arm, so construction now adopts that arm when the contextual union has exactly one: the remainder of the annotation is the nullish absence the value never is. Two different map arms stay refused (SC2003), because the layout would be ambiguous. Corpus 8528 pins the nullable, readonly and optional-field annotations, a parameter slot, iteration after the adoption, and remains byte-exact against Node. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>