Tips for effectively utilizing a javascript constructor in typescript

I am attempting to incorporate a Javascript library into my Typescript project. Within the JS library, there is a class called pdfjs-dist with a constructor that is used in this manner:

findController = new _pdf_find_controller.PDFFindController({
    linkService: pdfLinkService,
    eventBus: eventBus
});

The issue I am facing is how do I define PDFFindController in the .d.ts file so that I can utilize this constructor? I've attempted an approach like this:

class PDFFindController {
        constructor(linkService: LinkService, eventBus: EventBus) {}

However, I continue to encounter the problem of PDFFindController being undefined, thus preventing me from using the constructor.

Answer №1

Have you tried using pdf.js? If you downloaded it or added it from a CDN, it's recommended to use npm instead. There are existing typings available for it. To install everything properly, execute the following commands:

npm install pdfjs-dist
npm install -D @types/pdfjs-dist

In your code, make sure to include:

import { ... } from 'pdfjs-dist';

After completing these steps, the types should function correctly (as long as there are no errors in your tsconfig).

Answer №2

If you want to bypass type checking in TypeScript, the simplest solution is to designate the returned type as 'any'.

let (findController as any) = new _pdf_find_controller.PDFFindController({
linkService: pdfLinkService,
eventBus: eventBus});

Did that successfully resolve your issue, or are you looking for a specific type declaration?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for transferring information from the isolate scope to the parent scope

As a newcomer to AngularJS, I am exploring the creation of directives and how to invoke functions from the parent scope within them. While I have successfully achieved this, I am now grappling with the challenge of passing data from the isolate scope via a ...

Express.js: Communicating with internal microservices

I'm still learning about node.js, express.js and REST APIs. Here's the situation I'm facing: I have a requirement to retrieve user information from my database (using mongoDB) in various scenarios. What would be the recommended approach i ...

Showing changes in state in real-time using ReactJS: A quick guide

Hello, I am currently facing an issue while trying to add a comment and display it immediately on the DOM. Whenever I type any word in the form box, it does not appear in the box. Additionally, pressing the enter key does not trigger a POST request. Could ...

Having trouble retrieving information from combineLatest in Angular?

I'm having some trouble with fetching files to include in the post logs. It seems that the data is not being passed down the chain correctly when I attempt to use the pipe function after combining the latest data. This code snippet is part of a data r ...

Progressive Web App with Vue.js and WordPress Rest API integration

When creating an ecommerce website using Wordpress, I utilized Python for scraping data from other websites to compare prices and bulk upload products through a CSV file. My next goal is to learn Vue and transform the website into a PWA as it will be esse ...

Merge the movements of sliding a block along with the cursor and refreshing a sprite displayed on the block

Confronted with the challenge of combining 2 animations, one to move the block behind the cursor inside the container and the other to update the sprite on the block. Let me elaborate further on my issue. The block should only move when the cursor is insi ...

Why do I keep encountering the error of an undefined variable? Where in my code am I making a mistake

I am struggling to troubleshoot an issue with creating a simple ease scroll effect using the jQuery plugins easing.js and jquery-1.11.0.min.js. $(function(){ //capturing all clicks $("a").click(function(){ // checking for # ...

Avoiding the default action and using a false return value do not produce the

Despite trying preventDefault, return false, and stopImmediatePropagation, the page continues to redirect back to the first selection instead of redirecting to the textarea after inputting all required fields and clicking on the button. The issue persists ...

Fixing the problem of digest overflow in AngularJS

I've been working on a code to display a random number in my view, but I keep encountering the following error message: Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting! It seems to be related to a digest outflow issue, and I&apo ...

Is it possible to utilize JavaScript to access a .php file located in a separate directory?

Although I have been searching all day, I couldn't find a workout that specifically addresses my issue. I'm new to JavaScript and AJAX. Currently, I am exploring a web app called calendar.php located in the directory C:\xampp\htdocs&bs ...

Determine the HTTP request method when capturing AJAX responses

As I take control of all AJAX responses on a global scale, I find myself searching for an elegant solution to identify the method (such as POST/PUT/GET) that was initially used to make the request triggering the intercepted response. Below is my approach ...

items within an unordered list that can be collapsed

Answer: Nikhil was on the right track with his solution, but I had to make some modifications. Specifically, I needed to create and initialize an empty array to display the details properly. Here's the updated code: if (this.name.toLowerCase() == va ...

Type into the asp:TextBox and then click on my button, where it triggers a JavaScript function

So here's my issue: <asp:TextBox runat='server' /> <button id='b2'>hi</button> <script> $('#b2').click(function(e){ e.preventDefault(); alert('you clicked the button'); }); </script ...

Is there a way to fully load an entire HTML page on success using AJAX?

$.ajax({ type:'GET', url:"/" , data:{"user": user}, //user is a variable success:function(data) { I would like to display the entire HTML content received from my views here. } }); ...

Ways to confirm the validation of radio buttons in a form and implement CSS

I am having trouble adding validation to a form with radio buttons displayed as labels. I want to show a red border around the radios/labels or outer div when a radio button hasn't been checked before the user submits the form. I have attempted this ...

What could be the reason for the scope being empty in my AngularJS application?

I'm new to Angular and I'm currently customizing the tutorial for my app. However, I'm facing an issue with adding routes to my app. The templates are not being read correctly and the controller seems to have some issues as well. In order to ...

Can someone explain why I am consistently receiving the value of undefined when accessing the file Object?

Hi there, I'm new to this so I could really use some assistance... I'm currently working on an API where only registered users can upload a card with an image of their asset for rent. In my cards.js file, I have a post request that should respo ...

Is there a way to update the styling of specific sections of an input field as the user enters text in React?

Just like in most markdown editors, I am looking to enable the ability to modify parts of an input field as the user enters text. For instance: When the user types "_above_", as soon as the second underscore is typed, the text should be styled accordingly ...

Functionality of the Parameters Object

As I transition from using the params hash in Rails to learning Node/Express, I find myself confused about how it all works. The Express.js documentation provides some insight: 'This property is an array containing properties mapped to the named rout ...

Serving static files in Next.js with specific extensions without triggering a download

I'm facing an issue where I need to serve the stellar.toml file in domain/.well-known/stellar.toml with the content type as text/plain. The current configuration works only when the stellar file is saved without an extension. It is essential for me t ...