Closed awhitford closed 4 years ago
@awhitford Good question! We do export types such as TaxParams
and TaxForOrderRes
from the same package at the path taxjar/dist/util/types
.
For example, here's some sample code that uses the TaxParams
, TaxForOrderRes
, and TaxjarError
types:
import {
TaxForOrderRes,
TaxParams,
TaxjarError,
} from 'taxjar/dist/util/types';
export default (client): Promise<TaxForOrderRes> => {
const order: TaxParams = {
from_street: '2825 Sand Hill Rd',
from_city: 'Menlo Park',
from_state: 'CA',
from_zip: '94025',
from_country: 'US',
to_street: '5230 Newell Road',
to_city: 'Palo Alto',
to_state: 'CA',
to_zip: '94303',
to_country: 'US',
shipping: 14.99,
exemption_type: 'non_exempt',
nexus_addresses: [
{
country: 'US',
state: 'CA',
},
],
line_items: [
{
id: '0',
quantity: 1,
product_tax_code: '19005',
unit_price: 535.8,
discount: 267.9,
},
],
};
return client.taxForOrder(order).catch((err: TaxjarError | Error) => {
console.error(err);
return err
});
};
LineItem
is not currently an exported type (by itself). But it's exported as part of the appropriate param types and return types (CreateOrderParams
, CreateOrderRes
, etc.) so you still get type-checking and IntelliSense. But feel free to let us know if you'd like to request that other, more granular types be exported, such as LineItem
.
@awhitford So sorry for the late reply!! Funny story; I thought I posted this last week, but revisited this tab and it was still a draft...😅
Thanks for the issue! We could definitely use more documentation around TypeScript usage in the API Reference and guides as well, so we'll get that added to the backlog.
I can see from the source code that there are plenty of useful types available in
TaxjarTypes
. Alas, I cannot seem to access them...I am using TypeScript 3.9.5, NodeJS 10, and I have the recommended import:
How can I access things like
TaxParams
andLineItem
?