Default import doesn't work correctly with typescript moduleResolution node16
apottere opened this issue · comments
When I use "moduleResolution": "node16"
in my tsconfig.json
, I have to change my code as follows in order for it to compile:
import ShortUniqueId from 'short-unique-id';
// what I want to do
const generator = new ShortUniqueId(...);
// what I have to do
const generator = new ShortUniqueId.default(...);
It seems to be an issue with how the types are declared:
https://arethetypeswrong.github.io/?p=short-unique-id%405.0.3
That site claims that it might not work at runtime - this is something I haven't validated yet.
Confirm that there is problem on node16
and nodenext
.
It ends up with error like
error TS2351: This expression is not constructable.
Type 'typeof import("./node_modules/short-unique-id/dist/short-unique-id")' has no construct signatures.
I've added the following specs in order to address these concerns:
https://github.com/simplyhexagonal/short-unique-id/tree/main/specs
Even with these, I am unable to reproduce the symptom with the current code-base.
I will close this issue, but if you run into the same problem with default import, feel free to open a new issue and include steps to reproduce.
Cheers ✌🏼