Closed justinemmanuelmercado closed 4 years ago
Try putting the lazy codec last:
IncludedFeeDetailList: optional(ensureArray('IncludedFeeDetail', lazy(() =>FeeDetail)))
TS is complaining :/
Type 'Codec<{ FeeType: string; FeeAmount: { Amount: number | undefined; CurrencyCode: CurrencyCodeEnum; }; FeePromotion: { Amount: number | undefined; CurrencyCode: CurrencyCodeEnum; } | undefined; TaxAmount: { Amount: number | undefined; CurrencyCode: CurrencyCodeEnum; } | undefined; FinalFee: { Amount: number | undefined; CurrencyCode: CurrencyCodeEnum; }; IncludedFeeDetailList: FeeDetail[] | undefined; }>' is not assignable to type 'Codec<FeeDetail>'.
The types returned by 'decode(...)' are incompatible between these types.
Type 'Either<string, { FeeType: string; FeeAmount: { Amount: number | undefined; CurrencyCode: CurrencyCodeEnum; }; FeePromotion: { Amount: number | undefined; CurrencyCode: CurrencyCodeEnum; } | undefined; TaxAmount: { Amount: number | undefined; CurrencyCode: CurrencyCodeEnum; } | undefined; FinalFee: { Amount: number | undefined; CurrencyCode: CurrencyCodeEnum; }; IncludedFeeDetailList: FeeDetail[] | undefined; }>' is not assignable to type 'Either<string, FeeDetail>'.
Type '{ FeeType: string; FeeAmount: { Amount: number | undefined; CurrencyCode: CurrencyCodeEnum; }; FeePromotion: { Amount: number | undefined; CurrencyCode: CurrencyCodeEnum; } | undefined; TaxAmount: { Amount: number | undefined; CurrencyCode: CurrencyCodeEnum; } | undefined; FinalFee: { Amount: number | undefined; CurrencyCode: CurrencyCodeEnum; }; IncludedFeeDetailList: FeeDetail[] | undefined; }' is not assignable to type 'FeeDetail'.ts(2322)
Any ideas? If none, it's probably alright as an unknown array. Since Amazon's own API doesn't seem to follow the docs itself. Thanks for the help!
Your interface is wrong though, it says IncludedFeeDetailList?: FeeDetail
but the codec is IncludedFeeDetailList?: FeeDetail[]
, as mentioned in the error you posted. That is because of ensureArray
.
Ohh yeah you're right! I don't know why I didn't see that earlier.
TS still complained after though so I just copy pasted whatever was in the error and weirdly enough this is what worked for TS
interface FeeDetail {
FeePromotion: MoneyType | undefined
TaxAmount: MoneyType | undefined
FinalFee: MoneyType
FeeType: string
FeeAmount: MoneyType
IncludedFeeDetailList: FeeDetail[] | undefined
}
const FeeDetail: Codec<FeeDetail> = Codec.interface({
FeeType: string,
FeeAmount: MoneyType,
FeePromotion: optional(MoneyType),
TaxAmount: optional(MoneyType),
FinalFee: MoneyType,
IncludedFeeDetailList: optional(
ensureArray(
'IncludedFeeDetail',
lazy(() => FeeDetail),
),
),
})
If I tried replacing TaxAmount: MoneyType | undefined
with TaxAmount?: MoneyType
TS complained that they weren't equal.
Here's the commit to the fix if you're interested https://github.com/ScaleLeap/amazon-mws-api-sdk/pull/45/commits/0ed9e9f7db0fd16dc9d6a4abefd18bb8b50e1713
Thank you for the help 👍
Specifically for this line, it needs a reference to itself.
https://github.com/ScaleLeap/amazon-mws-api-sdk/blob/ee978e0955a6b127d02e836d96b9a8f9a9f1c2dd/src/sections/products.ts#L142-L143
I've tried using lazy like this
But typescript nags me about
FeeDetail
the interface not being equal to what's beeing calculated byCodec
Any help appreciated, @gigobyte