Currently, I am in the process of migrating an outdated JavaScript library to TypeScript for integration into Vue 3. However, I encountered an error message that states: 'new' expression, whose target lacks a construct signature, implicitly has an 'any' type.ts(7009). It seems like the issue stems from this particular code snippet within my package, yet the solution still eludes me. Below is the problematic code:
function Media(this: any, options: any ) {
this.clientOptions = options || {};
this.apiVersion = this.clientOptions.version || 'v1';
this.baseURL = `${this.clientOptions.server}/${this.apiVersion}`;
this.token = this.clientOptions.token || null;
this.files = null;
this.endpoints = this.clientOptions.endpoints || {
upload: 'files/upload',
chunk: 'files/upload/chunk',
auth: 'auth',
youtubeDownload: 'youtubes/download',
facebookDownload: 'facebooks/download'
};
this.chunkPhase = 'start';
this.chunks = [];
this.chunkActive = [];
this.chunkStartOffset = 0;
this.chunkMaxActive = this.clientOptions.maxActiveChunk || 3;
this.chunkMaxRetries = 1;
this.fileSize = 0;
this.chunkFile = null;
this.chunkSize = null;
this.chunkSessionId = null;
}
Media.prototype = {
getToken: async function () {
var self = this;
try {
var assignUrl = `${self.baseURL}/${self.endpoints.auth}`;
var data = {
'username': self.clientOptions.user.username,
'password': self.clientOptions.user.password
};
const response = await self._postx(assignUrl, data);
if (response.data && response.data.access_token) {
self.token = response.data.access_token;
}
return self.token;
} catch (error) {
return error;
}
},
}
...
Furthermore, here is the usage of the code in Vue which triggers the aforementioned error message:
import media from 'mediaLibrary'
const m3 = new Media(
{
server: 'myServer',
user: {
username: 'myUserName',
password: 'abc123'
},
version: 'v2',
endpoints: {
upload: 'files/upload',
chunk: 'files/upload/chunk',
auth: 'users/signin',
youtubeDownload: 'youtubes/download',
facebookDownload: 'facebooks/download'
}
});
I am hopeful that there exists a resolution to assist me in rectifying this issue...