Git Product home page Git Product logo

Comments (7)

BioSurienDG avatar BioSurienDG commented on June 2, 2024 1

@robobeau I think the actual API accepts either the numerical enum value or the string from my testing?

from avatax-rest-v2-js-sdk.

svc-developer avatar svc-developer commented on June 2, 2024

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.

from avatax-rest-v2-js-sdk.

robobeau avatar robobeau commented on June 2, 2024

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.

from avatax-rest-v2-js-sdk.

svc-developer avatar svc-developer commented on June 2, 2024

@BioSurienDG Correct, @robobeau Let us know if that doesn't work for you

from avatax-rest-v2-js-sdk.

uwitdat avatar uwitdat commented on June 2, 2024

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?

from avatax-rest-v2-js-sdk.

svc-developer avatar svc-developer commented on June 2, 2024

@uwitdat Yes, use the enums directly and it should work

from avatax-rest-v2-js-sdk.

oleg-codaio avatar oleg-codaio commented on June 2, 2024

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';?

from avatax-rest-v2-js-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.