I'm currently in the process of converting my JavaScript project to TypeScript, but I've hit a roadblock with an unresolved TypeScript error (TS2339).
Within my code base, I have a class defined like this:
export const devtoolsBackgroundScriptClient = new class
{
constructor()
{
return this.asProxy();
}
// some methods
asProxy()
{
return new Proxy(this, {
get: (e, t) => {
return void 0 !== e[t] ? e[t] : e.callBackgroundScript.bind(e, t);
}
});
}
callBackgroundScript(method, ...params)
{
// some code
}
}
I use this class by invoking it like so:
devtoolsBackgroundScriptClient.submitSurvey(surveyData);
The issue is that the submitSurvey method does not exist in the class, which is why it defaults to calling callBackgroundScript. This approach works fine in JavaScript, but TypeScript raises an error:
devtoolsBackgroundScriptClient.submitSurvey(surveyData);
Error Message: Property 'submitSurvey' does not exist on type 'devtoolsBackgroundScriptClient'
How can I go about resolving this TypeScript warning?