What is the recommended method for providing a type annotation to this
in a constructor?
function Client(options: ClientOptions) {
const defaultOptions = {
host: 'ws://127.0.0.1',
port: 8080,
logger: function() {
const prefix = "LOG:";
console.log.call(null, prefix, ...Array.from(arguments))
},
maxTime: 30000,
startFromTransactionId: 1
};
Object.assign(this, { ...defaultOptions, ...options });
this.transactionsCounter = 0;
this.requestCallbacks = {};
this.socket = null;
}
[ts] 'this' implicitly has type 'any' because it does not have a type annotation.
Explanation
I noticed that my text editor highlights each instance of using the this
keyword in this constructor. There is a [ts] warning indicating that no type annotation is provided for this.
Could you advise me on how to properly add a type annotation to this
?