0

I have variables declared in the .ts file:

export interface Payment {
     paymentStatus?: string
}

In the component.ts file, I create:

filters: PaymentFilters = {
paymentStatus: null
}

In console I get:

Type null is not assigned to type string

and

type string | null is not assigned to type string.

Why do I get such an error when I declare that the variable is a string and can optionally occur?

2
  • 1
    Use undefined instead of null? Commented Jan 10, 2023 at 17:16
  • Where does the error occur? What is the function signature for addToQueryParams? function addToQueryParams(variable: Payment, prop: string, value: string): string? Commented Jan 10, 2023 at 17:25

1 Answer 1

1

Adding the optional sign ? is equivalent to string | undefined. In Javascript as well as in Typescript, undefined and null are not of the same type.

you should then declared your interface as the following:

export interface Payment {
     paymentStatus: string | null
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.