An irritating problem with TypeScript-ESLint: when a Promise is returned without being resolved

Check out this TypeScript snippet I've simplified to showcase a problem:

import * as argon2 from "argon2";

export default async function(password:string):Promise<string>
{
    return argon2.hash(password, {
        type: argon2.argon2id,
        memoryCost: 32768,
        parallelism: 4,
        timeCost: 12
    });
};

The objective is to customize parameters for the Argon2 hash method. The code seems functional, but my ESLint setup is causing issues. Here's the pertinent part of my ESLint configuration:

        "require-await": "off",
        "@typescript-eslint/require-await": "error",
        "@typescript-eslint/promise-function-async": [
            "error",
            {
                "allowAny": false
            }
        ],

When the async keyword is included, it triggers the "require-await" rule

But removing the async keyword causes an issue with the "promise-function-async" rule

I'm contemplating:

  • If there's a more efficient way to configure ESLint
  • If there's a better approach to writing the function that avoids these problems (could it be pointing out a possible bug I'm overlooking?)
  • If using // eslint-disable-next-line is justified in this scenario

Answer №1

To get the encrypted hash of a password, use return await argon2.hash(...).

export default async function(password: string) {
    return await argon2.hash(password, { /* ... */ });
};
  • plugin:@typescript-eslint/require-await
    ensures that functions with no await do not need to be marked as async, avoiding unnecessary overhead.
  • plugin:@typescript-eslint/promise-function-async
    mandates that Promises in functions should always be marked as async to prevent them from being omitted in error stack traces if not awaited.

View this TypeScript example demonstrating how functions returning Promises without awaiting may skip the call stack in errors. Upon clicking Run, only createPromiseThatRejects and main appear in the call stack, while returnsPromiseThatRejects() is "skipped."

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

Easy steps to automatically disable a checkbox once the expiration date has been reached

I have this PHP code that retrieves values from my database. I want to prevent users from selecting or modifying items with expired dates. Could you assist me with this? The code below currently displays 'Expired' and 'Not Expired' on ...

Mastering Interpolation in React with TypeScript is essential for creating dynamic and interactive UI components. By leveraging the

Incorporating and distributing CSS objects through ChakraUI presents a simple need. Given that everything is inline, it seems the main issue revolves around "& > div". However, one of the TypeScript (TS) errors highlights an unexpected flagging of ...

Converting a Java Object array to a JavaScript Object Array when passing it as a

Is there a way to send a Java array of objects to a JavaScript function? Here is an example object: class SitioMapa{ String title; double lat; double lng; String description; public SitioMapa(String title,double lat,double lng,String ...

Remove a child node from its parent node in real-time

Currently, I am working on a project that involves adding and removing items as needed. The user interface can be seen in the image provided below: https://i.sstatic.net/Qhy2t.png Workflow: When the add icon is clicked, a new column is added for assignme ...

Utilizing Firebase in place of .json files for the AngularJS Phonecat application

I am currently exploring firebase and attempting to retrieve data using this service from firebase instead of json files. However, I have encountered some challenges in getting it to function properly. This is inspired by the angularjs phonecat example .f ...

Sending values to server-side function with JavaScript

Is there a way to invoke a code-behind function from JavaScript and pass parameters to it? For instance: <script> var name; <% createUser(name) %> </script> private void createUser(string Name) { // Do some complex operations } I&a ...

Trouble with NodeJS async/await - navigating through function arguments

Currently, I am attempting to perform web scraping using a particular library while implementing Node's async/await method in my code. Within the function named 'sayhi', I have created a variable 'page' and encountered an issue wh ...

Iterate through each image within a specific div element and showcase the images with a blur effect applied

I have a div with multiple images like this: <div class="am-container" id="am-container"> <a href="#"><img src="images/1.jpg"></img></a> <a href="#"><img src="images/2.jpg"></img>< ...

javascript limitation on self-executing code

I am facing an issue with my HTML file that contains self-executing JavaScript code (I specifically need the JavaScript to be internal, not from an external file). Upon inspecting in Chrome, I encountered the following error message: Refused to execute ...

Using a string as a query parameter in Javascript/AngularJS

Hey there! I have a username that I'm passing to retrieve a record from the database. Here's what I have in my controller: $scope.team=function(data) team_factory.getMember.query({}, data.username, function(data){ $scope.team=data; }); And ...

Vue-Routes is experiencing issues due to a template within one of the routes referencing the same ID

I encountered an issue while developing a Vue application with Vue-routes. One of the routes contains a function designed to modify the background colors of two divs based on the values entered in the respective input fields. However, I am facing two probl ...

A guide on simulating HTTP methods in Jest when dealing with private methods

I'm grappling with how to simulate the following functionality. I need to simulate both methods: getAllBookInCategory, deleteBookInCategory The public method invokes private methods and I presume I don't need to test private methods, only callin ...

How to access the result without using subscribe in Angular?

I am facing unexpected behavior with a method in my component: private fetchExternalStyleSheet(outerHTML: string): string[] { let externalStyleSheetText: string; let match: RegExpExecArray; const matchedHrefs = []; while (match = this.hrefReg.exe ...

Setting a TypeScript collection field within an object prior to sending an HTTP POST request

Encountered an issue while attempting to POST an Object (User). The error message appeared when structuring it as follows: Below is the model class used: export class User { userRoles: Set<UserRole>; id: number; } In my TypeScript file, I included ...

Twitter Bootstrap Dropdown PHP link fails to function

Recently, I designed a dropdown menu to be used on a PHP page. The main button, which contains the dropdown links, needs to still function as a link to another page. Despite following all the instructions provided on the Bootstrap website, the main button ...

How to use puppeteer to extract images from HTML that have alt attributes

<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 nopadding text-center"><!-- Start Product Photo --><div class="row"><img src="/products/ca/downloads/images/54631.jpg" alt="Product image 1">&l ...

The `diff` command is causing issues in `execSync`, resulting in errors when the files do not

Why am I getting an error with the diff command when my files don't match? let {stdout,stderr,err} = execSync(`diff output.txt answer.txt`, { cwd: "/home", encoding: 'utf8' }); if (err) { console.log(err); } console.log(stdout); The ...

What is the best approach to incorporating two distinct grid layouts within a single section?

I am attempting to replicate the header-graphic navigation found on this website: It appears that they are not using a grid for the header-graphic area, but rather keeping them separated as 2 divs within their Hero block container. I am interested in recr ...

After running JavaScript, retrieve the canvas data using the toDataUrl() method

After working on a Javascript function that creates a canvas and writes an image and text on it, I was expecting to get the base64 dataUrl. However, all I end up with is a blank canvas. Check out the code snippet below: function createBreadCrumb(label) ...

What sets the Test Deployment and Actual Deployment apart from each other?

I have been developing a web application using Google App Script and I currently have multiple versions of the same web app with various fields. Interestingly, when I run one version through a test deployment, it displays correctly as expected based on th ...