Bug Report
🔎 Search Terms
readonly parameter inferred tuple array args variadic
🕗 Version & Regression Information
- This is the behavior in every version I tried
⏯ Playground Link
Playground Link
💻 Code
declarefunctioncallFn<Textendsreadonlyany[]>(args: T,fn: (...args: T)=>void): void;declareconstinput: readonlystring[];callFn(input,(...args)=>{args;// readonly string[] ?})declarefunctioncallFnNonGeneric(args: readonlystring[],fn: (...args: readonlystring[])=>void): void;callFnNonGeneric(input,(...args)=>{args;// readonly string[] ?})🙁 Actual behavior
...args is readonly.
🙂 Expected behavior
...args is not readonly.
When this function is called, the input will be a brand new array which can be modified without affecting the caller:
> const fn = (...args) => { args[0] = "oops" }
undefined
> const arr = ["some", "values"]
undefined
> fn(...arr)
undefined
> arr
[ 'some', 'values' ]
Split out of #53258 (comment)
The "fix" here is to strip readonly from variadic args (at the top level). This also means the fix in #53258 can be reverted (as the real fix can be more general).
Bug Report
🔎 Search Terms
readonly parameter inferred tuple array args variadic
🕗 Version & Regression Information
⏯ Playground Link
Playground Link
💻 Code
🙁 Actual behavior
...argsis readonly.🙂 Expected behavior
...argsis not readonly.When this function is called, the input will be a brand new array which can be modified without affecting the caller:
Split out of #53258 (comment)
The "fix" here is to strip readonly from variadic args (at the top level). This also means the fix in #53258 can be reverted (as the real fix can be more general).