I have a code snippet that looks like this:
private get headers(): Headers {
const headers = new Headers();
headers.set('Authorization', `Bearer ${this.auth.tokenSnapshot}`);
return headers;
}
The variable headers
is defined as a constant. (This specific code is from Angular 4, so the Headers
class can be found here).
My question is, in TypeScript, is it acceptable to invoke a mutating method on an instance variable that has been declared as constant?
In C++, this would not typically be allowed unless the mutator method itself was declared as constant. However, I am unsure if the same rule applies in TypeScript.