Search code examples
typescript

Can a typescript parameter be annotated as const?


If I do not want the value of a parameter change within a function scope, is there any way to annotate that with Typescript?

I've tried:

function walk(const fileName: string): string[] {
// -----------^
}

But it does not work.


Solution

  • There is no way to do it right now, and it may not be, as it is not possible in ES6 either:

    How to make function parameter constant in JavaScript?

    This workaround doesn't work for TypeScript anyway.