Is there any way, with a macro library, an eslint rule, a tsconfig setting, a magic global.d.ts file, or otherwise, to make function arguments readonly by default?
// I want the compiler to turn this:
function foo(a: A[], b: Record<string, string> {
}
// Into this
function foo(a: ReadonlyArray<A>, b: Readonly<Record<string, string>> ) {
}
readonly b: numberas a function parameter. What do you mean by that? That nobody should be allowed to reassign a value to thebvariable inside the function body? If so, there's no facility for that, andReadonlyArray<A>doesn't do that foraeither. I'm confused; help!numbercase. Was thinking only of mutable arguments. When I started writing the question I hadfoo(args: {a: number, b: string}). That eslint rule seems useful to but my Q is about having functions not mutate mutable parameters.Record<string, string>into aReadonlyMap<string, string>? Those are different data structures entirely. Should the transformation also modify property accesses so that something likeb.barturns intob.get("bar")? Could you triple check what you're asking for and make sure that the code in your question constitutes a minimal reproducible example?