Typescript void cannot be assigned to the parameter type ProcedureListener

When attempting to call a function within my class, I encounter a warning/error in this particular section of the code:

rpc.register('cBrowser-SetUrl', (url: string, enableCursor: boolean) => {
    this.setBrowserUrl(url, enableCursor);
});

The error message is as follows: https://i.sstatic.net/3CqcE.png

Here's the complete code snippet:

const rpc = require('rage-rpc');

class BrowserSingleton {
    browser: BrowserMp;

    constructor() {
        this.browser = mp.browsers.new('http://package/cef/index.html');

        rpc.register('cBrowser-SetUrl', (url: string, enableCursor: boolean) => {
            this.setBrowserUrl(url, enableCursor);
        });
    }

    setBrowserUrl(url: string, enableCursor: boolean) {
        const path = `app.$router.push('${url}');`;

        this.setInteractState(enableCursor);
        this.pasteJS(path);
    }

    pasteJS(data: string) {
        this.browser.execute(data);
    }

    setInteractState(state: boolean) {
        mp.gui.cursor.visible = state;
        mp.game.ui.displayRadar(!state);
        mp.gui.chat.show(!state);
        mp.nametags.enabled = !state;
    }
}

new BrowserSingleton();

Any insights on why this issue is occurring would be greatly appreciated. Thank you for your help and suggestions.

Answer №1

When using the rpc.register() method, the callback function should have two parameters: args and info. To properly call this function, make sure to declare the callback as shown below:

rpc.register('cBrowser-SetUrl', (args: any, info: ProcedureListenerInfo) => {
  this.setBrowserUrl(url, enableCursor);
});

Keep in mind that the arguments url and enableCursor may not be available in the constructor yet. It is recommended to include them in the constructor signature or place the register call within the setBrowserURL function.

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

Make the source transparent to allow the background to shine through

Is there a way to make the source image of an img tag transparent, allowing the background image to show through? For example, if I have this html: <img src="my_image.jpg" height="200" width="300" style="background:url(img/bg.jpg) repeat;" /> I am ...

The Resharper guideline "Function Parameter" doesn't allow the usage of AngularJS service names

I have a question regarding naming conventions in my AngularJS app. Currently, all my service names start with an uppercase character. However, I am facing an issue where service parameters must match the service name, but Resharper's JavaScript "Func ...

Exporting a class from an index.ts file may result in a problem where the injected constructor is

Utilizing an index.ts file to manage exports, following the guidelines outlined in the Angular 2 style guide (https://github.com/mgechev/angular2-style-guide/blob/master/old/README.md#directory-structure), has been successful throughout my application deve ...

"Effortlessly emptying the text field with material-ui in React

I need assistance with clearing the content of two text fields and a button using Material-UI in React-JS. I am new to React and unsure how to achieve this. Below is the code I currently have: import React from 'react'; import RaisedButton from ...

Notify when a variable matches the value of a div

I am attempting to display an alert message when my JavaScript var is equal to the value of a div. Here is the code I'm using: function checkMyDiv() { var elementCssClass = document.getElementById("Target"); if (elementCssClass == "hello") ...

Unselecting an "all selected" checkbox

I need help with my checkbox functionality. Currently, I have a checkbox that selects all options when clicked, but if one option is deselected, the "Select All" option remains checked. Any guidance on how to address this issue would be greatly appreciated ...

Is there a way to identify if the parent page has completed loading while within an iframe?

Is there a way to detect properties or events within the iframe that can help determine this? The src of the iframe and the parent page belong to different domains. ...

Explaining the way jQuery data() eliminates circular references

After reading an explanation about the benefits and implementation process, I still have a question - how exactly does it eliminate the circular reference?. Can you explain how the circular reference is broken? $(div1).data('item', div2); $(div ...

Incorporating JavaScript to dynamically load an HTML page into an iframe

I am attempting to have each option load a unique page within a frame <!DOCTYPE html> <html> <head> <script> function selectCountry() { var mylist=document.getElementById("country"); document.getElementById("frame").src=mylist.opti ...

Tips for conducting unit tests on navigator.notification.alert

I am currently facing a challenge in writing a unit test for a JavaScript function where I need to fake the navigator.notification.alert method. Can anyone provide suggestions or solutions? Below is the code snippet that I have attempted: navigator = { ...

`To filter out JSON data that does not exist in Javascript, follow these steps:``

Utilizing JavaScript Fetch to retrieve JSON data, I am aiming to present the information in a well-arranged HTML layout. I encountered challenges when attempting to process certain content. The majority of the data objects I am parsing include images that ...

Deactivate a function within Bootstrap JavaScript

Is there a way to temporarily disable a function within Bootstrap after a click event? <a href="#"><span class="glyphicon glyphicon-triangle-right" id="btn04" onclick="myfun();"></span></a> Additionally, I am looking for a soluti ...

Searching Firestore arrays for objects based on one of two fields

Within my document, I am working with the following array: https://i.sstatic.net/j9hBT.png I have a SizeFilterComponent that emits a BaseFilter object when a size is selected. Multiple sizes can be selected. Here is the method handling this logic: selecti ...

JavaScript Code for Executing Function on Checkbox Checked/Unchecked

My goal is to display an image when the checkbox is checked and show text when it is unchecked. However, I am facing an issue where the text does not appear when I uncheck the checkbox. <input type="checkbox" id="checkword" onchang ...

Is there a way to prevent a form from automatically submitting once all inputs have been completed? (Using react-hook-form)

After creating a multi-step-form using shadcn, next, zod, and react-hook-form, I encountered an issue where the form is being submitted on step 3 instead of when clicking the submit button. form.tsx const form = useForm<Inputs>({ resolve ...

What is the most efficient way to update all elements within an array in a MongoDB document to a specific value?

Imagine a scenario where I possess the subsequent document: { _id: ObjectId("5234cc89687ea597eabee675"), code: "xyz", tags: [ "school", "book", "bag", "headphone", "appliance" ], qty: [ { size: "S", num: 10, color: "blue" }, ...

It appears that the functions in linqts are not clearly defined

Currently, I am in the process of learning Angular4 and facing challenges with getting linqts to function properly. Within my room-list.component.ts file, I include it in this manner: import { List } from 'linqts'; A few lines below, I have my ...

Using Typescript in conjunction with nodemon and VS Code for seamless integration of declaration merging

After adding a middleware to my express app app.use(function(req: express.Request, res: express.Response, next: express.NextFunction) { req.rawBody = 'hello2'; next(); }); I also included custom.d.ts declare namespace Express { expor ...

Exploring MVC 5's View and Controller Components

In my GetCourseList.cshtml file (view), I have the following code that displays fetched information from the database: @model IEnumerable<WebApplication8.Models.Courses> @{ Layout = null; } <!DOCTYPE html> <html> <head> ...

Ways to adjust the content width within an iframe without altering the iframe's overall width

I need help with adjusting the width slider in my iframe. I want the width slider to control the content width within the iframe, not the actual width of the iframe itself. Essentially, I want to switch between mobile and desktop mode by resizing the con ...