When I write typescript:
I have this code:
import * as express from 'express'
and the system gives me an error:
Type originates at this import. A namespace-style import cannot be called or constructed, and will cause a failure at runtime. Consider using a default import or import require here instead.
So, I change to:
import express from 'express'
what is the difference between them, why the first way can not called or constructed?
what is the difference between them
* as express will import the entire contents of a module express is will import the default export only why the first way can not called or constructed?
A module itself is not callable as per the ES spec. So you wouldn't be able to do express() i.e. a function invocation. Therefore it must mapped to a member of the module, in this case the default export member 🌹
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With