The 'Promise<void>' type cannot be assigned to the 'Promise<xxx>' type

Attempting the following transaction in TypeScript resulted in a compile error. The error message stated:

Type 'Promise<void>' is not assignable to type 'Promise<transactionArgument>'
. However, the function returns a value of type transaction, which is of type transactionArgument.

I am puzzled by this issue and would greatly appreciate any insights or opinions on why it occurred.

type RegisterPricingTransactionInfo = (pricingTransaction:transactionArgument,createdAt:Date,createdBy:string,datasource:any) => Promise<transactionArgument>

export const  registerPricingTransactionInfo: RegisterPricingTransactionInfo = async (pricingTransaction,createdAt,createdBy,datasource) => {
    let urlCode;
    let transaction:transactionArgument;
    transaction = {test:"test"}

     await datasource.manager.transaction(async (transactionalEntityManager:EntityManager) =>{
     try {
        await transactionalEntityManager.save(transaction)
        return transaction;
     } catch (error) {
        console.error(error)
     }
    })
}
    "message": "Type '(pricingTransaction: transactionArgument, createdAt: Date, createdBy: string, datasource: any) => Promise<void>' is not assignable to type 'RegisterPricingTransactionInfo'.\n  Type 'Promise<void>' is not assignable to type 'Promise<transactionArgument>'.\n    Type 'void' is not assignable to type 'transactionArgument'."

Thank you for your help.

Answer №1

You are dealing with a situation where you have a nested callback. The inner callback is properly returning data, but the outer parent function is not.

One possible solution to identify the issue could be to ensure proper code indentation. This can help in spotting the problem more easily:

const recordPricingTransaction: RecordPricingTransaction = async (pricingTransaction, createdAt, createdBy, datasource) => {
  let urlCode;
  let transaction: transactionArgument;
  transaction = { test: "test" }

  await datasource.manager.transaction(async (transactionalEntityManager: EntityManager) => {
    try {
      await transactionalEntityManager.save(transaction)
      return transaction; // this return statement is within the nested callback
    } catch (error) {
      console.error(error)
    });
    // no return statement outside the nested callback?
}

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

What is the best way to form a new type that encompasses all shared properties found within a union of types?

Is there a method to safely map over the union of arrays without hard-coding specific types? When attempting to calculate newArr1, an error is encountered: Property 'field2' does not exist on type 'Common<A, B>'. How can this err ...

Tips for properly implementing an enum in TypeScript when using the React useState hook

What's the correct way to utilize my useState hook? I have this enum type: export enum Status { PENDING = 'pending', SUCCESS = 'success', ERROR = 'error', } And the useState hook: const [isValid, setIsValid] = use ...

Changing the target in tsconfig.json to "es2022" leads to the error message "Property 'xx' is referenced before its initialization.ts(2729)"

My Angular code is filled with instances where I assign a property at its definition like this... public data$ = this.service$.fetchData; constructor(private service$: MyService However, after updating my tsconfig.json target to "es2022", I encountered ...

Typescript UniqueForProp tool not working as expected

I've created a utility function called UniqueForProp that takes an array of objects and a specified property within the object. It then generates a union type containing all possible values for that property across the array: type Get<T, K> = K ...

Error: The selected module is not a valid top-level option

I am facing an issue while using the babel-loader. I have removed all irrelevant code and just kept the error-related portion. What could be causing this problem? module.exports = merge(baseWebpackConfig, { ... module: { rules: [ ...

Querying subdocuments within an array using MongoDB's aggregation framework

Currently, I'm facing a challenge while developing a statistics dashboard for a meditation app. I'm struggling with creating a MongoDB query to fetch the most popular meditations based on user progress. The key collections involved are users and ...

The TypeScript rule in the project-specific .eslintrc.js file is not being applied as expected

Currently, I am following a tutorial on Ionic/Vue 3 which can be found here. However, when I try to serve the project, I encounter the following error: https://i.stack.imgur.com/k4juO.png It appears that my project-level .eslintrc.js file is not being ap ...

What is the process for converting/executing TypeScript into JavaScript?

Having trouble running https://github.com/airgram/airgram Encountering this warning message from the post (node:9374) Warning: To load an ES module, set "type": "module" Have already added {"type": "module"} To pa ...

Facing Syntax Errors When Running Ng Serve with Ngrx

Currently, I am enrolled in an Angular course to gain proficiency in ngrx. In a couple of months, I will be responsible for teaching it, so I am refreshing my memory on the concept. Strangely, even after installing it and ensuring my code is error-free, er ...

Steps for integrating a valid SSL certificate into a Reactjs application

After completing my ReactJS app for my website, I am now ready to launch it in production mode. The only hurdle I face is getting it to work under https mode. This app was developed using create-react-app in a local environment and has since been deployed ...

Instead of the type definition file, navigate to the TypeScript source file within VS Code

A unique npm library I developed is utilized in various main projects, with all the sources stored within a /src directory and written in TypeScript. The compiler options listed in the tsconfig.json file include "sourceMap": true and "outDir": "dist". Addi ...

Avoid displaying the value in Ant Design's autocomplete feature

Can someone assist me with clearing the auto complete placeholder or displaying only part of the label instead of the value after a user selects from a drop-down list? The current setup shows the unique ID as the value, which we want to keep hidden from en ...

Cease the interval once the array is devoid of elements

I'm currently working on simulating typing effects for incoming server messages by adding an interval to the output. Here's what I have so far: const stream = interval(1000) .pipe( map((): Message => { return messages.pop(); }) ); ...

The name property of event.currentTarget is now being returned as currentTarget

I am facing an issue with my handleChange function in typescript. When I try to retrieve the name attribute from a text field and log it, it returns 'currentTarget' instead of the assigned name. Additionally, the value is showing up as undefined. ...

Stop the direct importing of modules in Angular applications

I have a feature module that declares components and also configures routing through a static function. @NgModule({ declarations: FEATURE_COMPONENTS, entryComponents: FEATURE_COMPONENTS, imports: [ UIRouterModule, ... ] }) export class Fea ...

The ngFor directive encounters issues when placed within a quotation mark or when used within a Bootstrap Tooltip Tag

.HTML File : I encountered an error saying, "Identifier 'mg' is not defined." However, {{mgr[0].value}} works <button type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="bottom" ...

Troubles with Katex/ngx-markdown Display in Angular 16

In my Angular 16 application, I utilize the ngx-markdown library alongside Katex and other dependencies. A challenging situation arises when the backend (an LLM) responds with markdown text that conflicts with Katex delimiters during rendering. I attempte ...

Guide on deactivating the div in angular using ngClass based on a boolean value

displayData = [ { status: 'CLOSED', ack: false }, { status: 'ESCALATED', ack: false }, { status: 'ACK', ack: false }, { status: 'ACK', ack: true }, { status: 'NEW', ack ...

The 'formGroup' property cannot be bound as it is not recognized as a valid property of 'form' in Angular 7

I tried implementing a login feature using web API with Angular 7, but encountered an error when using <form [formGroup]="loginForm" (submit)="loginFormSubmit()">. What could be causing this issue? login.component.html <form [formGroup]="loginFo ...

Is your Typescript compilation running into a problem with jwt tokens?

Having issues while trying to compile a typescript file as the compiler is throwing an error message: Error: TS2339 - The property 'payload' does not exist on type 'string | object'. Property 'payload' does not exist on type ...