The data type 'null' cannot be assigned to type ** in TypeScript

I have created a sample class that registers some data to the database, shown below.

export class RegisterPricingTransactionInfo {

    private pricingTransaction: TransactionArgument = null;

    constructor(pricingTransaction: TransactionArgument) {
        this.pricingTransaction = pricingTransaction;
        this.registerPricingTransactionInfo();
    }

    private urlCode = new GenerateUrlCode(
        this.pricingTransaction.npServiceDivision,
        this.pricingTransaction.companyCode,
        this.pricingTransaction.shopBranchCode,
        this.pricingTransaction.shopRegistrationDateSeq,
        this.pricingTransaction.shopCode,
        this.pricingTransaction.npTransactionId).getUrlCode();
    
    private transaction: ExecuteTransaction = {
        npServiceDivision       : this.pricingTransaction.npServiceDivision,
        shopCode                : this.pricingTransaction.shopCode,
        npTransactionId         : this.pricingTransaction.npTransactionId,
        companyCode             : this.pricingTransaction.companyCode,
      
    };

public registerPricingTransactionInfo: RegisterPricingTransactionInfo = async () => {

        await getRepository(PricingTransaction)
            .createQueryBuilder()
            .insert()
            .into(PricingTransaction)
            .values([this.transaction])
            .execute();
        return this.transaction;
}

However, I came across the following error:

How can I initialize pricingTransaction? Thank you

Type 'null' is not assignable to type 'TransactionArgument'.

https://i.sstatic.net/Dd2VL.png

https://i.sstatic.net/OWIit.png

Answer №1

element, it is recommended to declare the variable pricingTransaction in the following manner:
private pricingTransaction: transactionArgument | null = null;
Alternatively, it would be more efficient to define this variable within the constructor itself as shown below:
    constructor(private pricingTransaction: transactionArgument){
        this.registerPricingTransactionInfo
    }

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

The findById function is encountering errors only on invalid id inputs: Unable to cast value to ObjectId

I have implemented a basic GET method to retrieve a 'genre' from a MongoDB database based on an id, using Mongoose. It functions correctly when a valid id is provided, but crashes the application when an invalid id is used. Here is the code snip ...

Activate the mouseenter event as soon as an animated element makes contact with the cursor

As I venture into the world of web development, I am currently working on creating a game where the main objective is to avoid touching moving circles with the cursor. My approach involved using a mouseenter event as shown in the JSFiddle example below: $ ...

Enhancing functionality with extra JavaScript tags in next.js

Recently, I delved into programming with react & next.js after previously working with node.js. It didn't take long for me to create my first application, but upon inspecting the page, I noticed an abundance of extra JavaScript code (see image below). ...

How can I set a global variable and incorporate it into other functions in jQuery or JavaScript?

Define jQuery global variables: $.customnamespace = { customVar : "initial" }; I am going to work with XML data, then update the value of customVar and invoke the test() function to change the value of customVar again. I want the value of the varia ...

Server unable to retrieve jQuery file

Strange issue with my HTML file not fetching the jquery.js file, even though typing the exact URL into a new browser tab retrieves it successfully. The code snippet looks like this: <script src="js/jquery.js"></script> You can find my websit ...

Why won't my navigation bar stay in place when I scroll down on the screen?

I'm trying to create a sticky navigation bar that becomes fixed when the user scrolls down to 200 pixels, but it's not working properly. I want it to behave like in this example: import React,{useState,useEffect} from 'react' functio ...

When attempting to retrieve the value of my select element, I encounter difficulty due to a hidden field that only becomes visible when a certain option is selected

I have a dropdown menu with different options, including one labeled "other". When the user selects "other", a hidden text field appears for them to enter a custom value. This functionality works correctly. However, if the user selects any other option and ...

Ways to create a versatile function for generating TypedArrays instances

I'm working on a function that looks like this: export function createTypedArray<T extends TypedArray>( arg : { source : T, arraySize : number } ) : T { if( arg.source instanceof Int32Array ) { return new Int32Array( arg.arraySize ); } ...

Rotate the cylinder according to the normal vector of the tube endpoint

I'm working on creating a curved 3D arrow using three.js. My approach involves using a Tube along a curved path and a Cone shaped cylinder. Here's how they currently look: https://i.sstatic.net/jmVB6.png https://i.sstatic.net/P756z.png My goal ...

How can I display all dates on the x-axis in Highcharts datetime xAxis labels, rather than just the even dates?

I'm facing a dilemma with Highcharts and need assistance. My issue is regarding the display of all dates on the x-axis, as it seems only even dates are being shown by default. Is there a way to show all dates? https://i.sstatic.net/uLTP1.png Below is ...

Access your own data, shared data, or designated data with Firebase rules

Seeking guidance on implementing firebase rules and queries for Firestore in a Vue.js application. Requirement: User must be authenticated User can read/write their own data entries User can read data with "visibility" field set to "public" User can rea ...

Tips for Using AJAX and JavaScript to Save an XML File

My current task involves attempting to insert an element into an XML file. Upon inspecting the program with a debugger, I noticed that the element is successfully added to the XML file. However, when I stop the program from running, the changes are not sav ...

Can you use a lightbox to showcase multiple images while only displaying one image at a time to trigger them?

Currently, I am utilizing Lightbox in order to showcase photos. For example, I have divided the photos into two categories: "work" and "vacation". To implement this, I would follow this code snippet... <a href="images/image-1.jpg" rel="lightbox[work]"& ...

Finding the location of PIE.htc in the Firebug tool

After encountering issues with CSS3 properties not working on IE 7 and IE 8, I decided to include PIE.HTC. Visit this link for more information Upon viewing the page in IE, I realized that the CSS3 properties were not being applied as expected. I attempt ...

Utilizing the Angular slice pipe within innerHTML: A comprehensive guide

I have a whatsNewDetail.content string that includes HTML elements: <span style="font-family: &quot;Open Sans&quot;, Arial, sans-serif; font-size: 14px; text-align: justify;">In nec convallis justo. Quisque egestas mollis nibh non h ...

Creating an object structure in React Native based on existing data sources

I've encountered a unique object structure within a specific library that looks something like this: const libraryTemplateData = [ { eventContainerStyle: { style: { opacity: 1, }, }, ...

JQuery misinterpreting data from server's CSV file

My project involves running a program on the Raspberry Pi to capture GPIO inputs and store them in a .csv file, which is then read by a JavaScript script to display data on a web page hosted on the Pi. The Raspberry Pi constantly checks the status of the ...

"Guide to terminating an AWS Batch job that is in a RUNNABLE state using the JavaScript SDK

I need assistance with canceling a job stuck in runnable status on AWS Batch using the JavaScript SDK. Which API option should I choose? 1. The TerminateJobCommand documentation states that it terminates jobs in the STARTING or RUNNING state, causing them ...

The function firebase__webpack_imported_module_2__.auth.createuserwithemailandpassword does not exist

I'm facing an issue with my Firebase setup in my code. The browser console is showing that auth.createUserWithEmailAndPassword() is not a function. Can someone help me troubleshoot this problem? Here's the relevant code from login.js import React ...

Refresh the DOM following a jQuery load operation

Recently, I integrated the Jquery Load($('body').load('/some.html')) function into my application. There are plenty of other jquery codes in my application initialized as $('#id'). Instead of transforming all these codes into ...