title: Typescript: import * as moment from 'moment' vs. import moment from 'moment'
body: <p>I'm having a weird issue with Typescript and importing the <code>moment</code> package. I've seen it in a couple of different places, and I've even seen it crop up in the same file depending on whether or not I added a specific static method to a class.</p>
  
  <p>The problem is this:</p>
  
  <p>When I import moment with <code>import * as moment from 'moment';</code>, I get no Typescript errors, but I do get an issue with my tests; specifically, they fail with <code>TypeError: moment is not a function</code>.</p>
  
  <p>When I change the import the <code>import moment from 'moment';</code>, the code works, but I get <code>"moment" has no default export</code>.</p>
  
  <p>I don't understand the difference between these. I've seen other questions (like <a href="https://stackoverflow.com/q/36893165/2008384">this one</a>, which recommends the first syntax). The a comment on the accepted answer to the question above suggests turning on the <code>allowSyntheticDefaultImports</code> flag, which <em>does</em> correct the issue, but I'm a little concerned about that flag. <a href="https://www.typescriptlang.org/docs/handbook/compiler-options.html" rel="noreferrer">The documentation</a> says:</p>
  
  <blockquote>
    <p>Allow default imports from modules with no default export. This does not affect code emit, just typechecking.</p>
  </blockquote>
  
  <p>which seems to imply that there is no typechecking for modules imported in this way.</p>
  
  <p>So, two questions:</p>
  
  <ol>
  <li>Am I understanding the TS documentation for the <code>allowSyntheticDefaultImports</code> flag correctly? Is it turning off typechecking for the <code>moment</code> package?</li>
  <li>Is there a way to (consistently) import this package?</li>
  </ol>
  
  <p>FWIW, I'm using Typescript 3.4.5 and moment 2.24.0.</p>