Can't create new client with Typescript - Docs example doesn't work
eliezra236 opened this issue · 4 comments
Hi,
trying the following doesn't work
import Avatax from 'avatax';
const client = new Avatax(config)
Getting an error This expression is not constructable.
Trying as const client = new Avatax.default(config)
works for TS lint but then fail on runtime becasue TypeError: Avatax.default is not a constructor
How can I create a new client?
Currently I do the following (which works):
import Avatax from 'avatax';
import type AvaTaxClient from 'avatax/lib/AvaTaxClient.js';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const client: AvaTaxClient.default = new Avatax(config)
@svc-developer thank you for your reply.
I am using "module": "NodeNext",
@eliezra236 Could you provide your entire tsconfig.json, I am still able to get my test application to compile using the NodeNext option. Also, it is failing when you run tsc ./<script_name>
correct?
@eliezra236 Okay so I figured it out.
Check your tsconfig.json file, if you have "esModuleInterop" set to true. then you can use the import syntax.
Otherwise, change the line above to this const Avatax = require("avatax");
and all of the errors should go away.
The other option is to set esModuleInterop to true :) Please feel free to open another issue or comment here if this does not solve the issue.