I am getting below error
"Argument of type ‘string | undefined’ is not assignable to parameter of type"
I don’t know how to solve that error.. here is my code
export interface IDropDown {
label: string;
value: string;
}
export enum BOOKING_TYPE {
FC = 'FC',
LC = 'LC',
TUFFING = 'TUFFING',
}
export interface IImportBookingData {
booking_type: IDropDown | null;
}
let bookingData: IImportBookingData;
const iscl = [BOOKING_TYPE.LC, BOOKING_TYPE.TUFFING].indexOf(bookingData?.booking_type?.value) !== -1;
console.log(iscl)
code Link
any idea ?
2
Answers
The type
booking_type
is defined asIDropDown
. But, later your are accessing thevalue
prop of thebooking_type
inside theindexOf
.Here, the
value
isstring
and it will show the type error. To overcome that, you need to type cast the value.Here the
as BOOKING_TYPE
will take care the type casting errors.Also check this solution
Hope this solves your problem.