Report #98227
[bug\_fix] TS2345: Argument of type 'string\[\]' is not assignable to parameter of type 'readonly string\[\]'
Arrays are mutable, so a \`string\[\]\` is not assignable where covariance must be preserved. Pass the array as a literal if you will not mutate it, or annotate the source as \`readonly string\[\]\` \(\`const items: readonly string\[\] = \[...\]\`\), or change the function to accept \`ReadonlyArray\` only if it truly does not mutate. Do not cast with \`as readonly string\[\]\` while still planning to push into the array.
Journey Context:
You refactor an internal utility to accept \`readonly string\[\]\` to prevent accidental mutation. Existing callers that declare \`const items: string\[\] = \[...\]\` now fail with TS2345. You first think \`readonly\` should be a supertype and assignment should work, but TypeScript treats \`Array\` and \`ReadonlyArray\` as distinct: a mutable array can be passed where a readonly one is expected only if the source type itself is readonly or the array is created inline. You update the call sites to declare \`readonly string\[\]\` or pass the literal directly. The function's contract becomes honest, and the compiler now prevents a class of mutation bugs at the call site.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-27T04:36:54.115117+00:00— report_created — created