type UpdateConsumerT = {
obj: {
min_quantity: number
fixed_price: number
date_start: string | boolean
date_end: string | boolean
}
}
type UpdateProducerT = {
obj: {
min_qty: number
price: number
date_start: string | boolean
date_end: string | boolean
}
}
export async function updatePricelistItem(
pricelist_item_id: number,
obj: UpdateConsumerT,
isProduction: false
): Promise<number>
export async function updatePricelistItem(
pricelist_item_id: number,
obj: UpdateProducerT,
isProduction: true
): Promise<number>
export async function updatePricelistItem(
pricelist_item_id,
obj,
isProduction = false
) { ... }
I have this function, and i try to use overloads
But for some reason it says
Parameter ‘pricelist_item_id’ implicitly has an ‘any’ type.ts(7006)
My question is, what am i doing wrong here?
>Solution :
You will need to explicitly specify the parameter types and return type on the implementation:
type UpdateConsumerT = {
obj: {
min_quantity: number
fixed_price: number
date_start: string | boolean
date_end: string | boolean
}
}
type UpdateProducerT = {
obj: {
min_qty: number
price: number
date_start: string | boolean
date_end: string | boolean
}
}
async function updatePricelistItem(
pricelist_item_id: number,
obj: UpdateConsumerT,
isProduction: false
): Promise<number>
async function updatePricelistItem(
pricelist_item_id: number,
obj: UpdateProducerT,
isProduction: true
): Promise<number>
async function updatePricelistItem(
pricelist_item_id: number,
obj: UpdateProducerT | UpdateConsumerT,
isProduction = false
): Promise<number> { return new Promise(() => {}) }
