Reputation: 109
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?
Upvotes: 0
Views: 798
Reputation: 894
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
}
Upvotes: 1