Closed BioSurienDG closed 1 year ago
Fixed in release 23.3.0 Please give it a try and let us know if you have any further issues https://github.com/avadev/AvaTax-REST-V2-JS-SDK/releases/tag/23.3.0 You'll have to opt-in to the feature by passing in enableStrictTypeConversion: true
to the constructor for the SDK.
There's still a problem, here, @svc-developer.
The typing for createTransaction
is expecting a model
that has a type
property defined as
/**
* @type {Enums.DocumentType}
* @memberof CreateTransactionModel
*/
type?: Enums.DocumentType | undefined;
But the documentation suggests that we need to be using a string
, for example "SalesInvoice"
instead of the enum value for DocumentType.SalesInvoice
, which is 1
.
@robobeau I think the actual API accepts either the numerical enum value or the string from my testing?
@BioSurienDG Correct, @robobeau Let us know if that doesn't work for you
I have to convert the type to unknown before I can type it when using a string here.
const taxDocument = formatTaxDocument({
type: 'SalesInvoice' as unknown as CreateTransactionModel['type'],
shippingAddress: formattedShippingAddress,
items,
customerId,
commit: false,
currencyCode: 'USD',
})
export function formatTaxDocument(params: TaxDocumentParams) {
const taxDocument: CreateTransactionModel = {
type: params.type,
companyCode: process.env.AVATAX_COMPANY_CODE,
date: new Date(),
customerCode: params.customerId || 'N/A',
addresses: {
shipTo: params.shippingAddress,
shipFrom: {
locationCode: process.env.AVATAX_LOCATION_CODE,
},
},
lines: params.items,
commit: params.commit,
currencyCode: params.currencyCode,
}
return taxDocument
}
If I remove the parsing I get this TS error
Type 'string' is not assignable to type 'DocumentType | undefined'.ts(2322)
index.ts(43, 3): The expected type comes from property 'type' which is declared here on type 'TaxDocumentParams'
What's the best practice here? Is it using DocumentType.SalesInvoice
?
@uwitdat Yes, use the enums directly and it should work
Just ran into this issue as well. Maybe you could make enableStrictTypeConversion: true
required in TypeScript in the AvaTaxClient
constructor? That way for folks using TypeScript, they'll get the correct behavior. Those using JS can fall back to the default of string enums. (Side note, I do think numeric enums by default are a mistake and strings would be much more friendly.)
Also could you export enums and models from the top-level avatax
module so we don't need to reach into the import and have to write import * as AvaTaxEnums from 'avatax/lib/enums/index';
?
The typescript for the SDK says that when you call
.createTransaction
it should return a transaction model wheretype
is an enum as defined here: https://github.com/avadev/AvaTax-REST-V2-JS-SDK/blob/master/lib/models/TransactionModel.ts#L56-L60As you can see the return type of the function
createTransaction
should populatetype
as anumber
. However, from inspecting the result in the debugger it is actually astring
not anumber
(see screenshot).This should be fixed (either the type needs to change or the API result should change to match the expected enum).
Same issue for
status
field on the returned transaction (i.e. it uses thestring
representation instead of the numeric value from theDocumentStatus
enum)