I'm having difficulty strongly typing my Twitter widget.
At the moment, it throws me a bunch of errors including:
ESLint: Unsafe call of an any typed value.(@typescript-eslint/no-unsafe-call)
ESLint: Unsafe member access .catch on an any value.(@typescript-eslint/no-unsafe-member-access)
ESLint: Unsafe member access .createTweet on an any value.(@typescript-eslint/no-unsafe-member-access)
ESLint: Unsafe member access .finally on an any value.(@typescript-eslint/no-unsafe-member-access)
ESLint: Unsafe member access .then on an any value.(@typescript-eslint/no-unsafe-member-access)
I'd like to fix this by creating an interface for the twi, but I'm unsure what that would look like.
loadTwitterWidget(): void {
this.setLoadingStatus.emit(true);
this.courseContentElementEmbedTweetService
.loadScript()
.pipe(take(1))
.subscribe(
// I want to create an interface for this
(twitter) => {
(this.tweet.nativeElement as HTMLElement).innerHTML = null;
// Errors occur here
twitter['widgets']
.createTweet(this.courseContentElementEmbed.id, this.tweet.nativeElement, {
...this.tweetOptions,
})
.then((r) => {
if (!r) {
this.setErrorStatus.next();
} else {
this.setSuccessStatus.next();
}
})
.catch((error) => this.logger.error(error))
.finally(() => this.setLoadingStatus.emit(false));
},
(error) => this.logger.error(error)
);
}
So far I've tried the following:
export interface ICourseContentElementEmbedTweetWidget {
widgets: {
createTweet: unknown
}
[key: string]: string;
}
But I get the error TS2411: Property 'widgets' of type '{ createTweet: unknown; }' is not assignable to string index type '.
You can provide it as any like below or you can navigate to modules by pressing F12 if using vscode and search for createTweet you will get its data type there.