0

What's the difference between

import * as express from 'express'

and

import express from 'express'

and why I am being "obliged" to use the first one by tsloader?

If I use the second version, I got undefined

Rodrigo
  • 135
  • 4
  • 45
  • 107
  • This has been asked before over here: https://stackoverflow.com/a/35706271/2919534 – Mark Atkinson Feb 01 '21 at 21:16
  • 3
    I'm sure it's been asked before but that question isn't exactly the same. If the module does not declare a `default` export, then `import express from 'express'` is a "synthetic default export" which basically packages all of the exported vars into properties of an `express` object, the same as `import * as express from 'express'` does. You can only use `import express from 'express'` if your `.tsconfig` has `"allowSyntheticDefaultImports": true`. – Linda Paiste Feb 02 '21 at 01:39
  • @LindaPaiste I just checked and I have `allowSyntheticDefaultImports true`. Thanks for the explanation! – Rodrigo Feb 02 '21 at 12:41

0 Answers0