title: Sequelize associations
body: <p>I am working on a Typescript Sequelize project, where my <code>/models/index.ts</code> file has the following "import all models in this directory" function:</p>
  
  <pre><code>var basename = path.basename(module.filename);
  fs
      .readdirSync(__dirname)
      .filter(function (file) {
          return (file.indexOf('.') !== 0) &amp;&amp; (file !== basename) &amp;&amp; (file.slice(-3) === '.js');
      })
      .forEach(function (file) {
          console.log(file);
          var model = sequelize['import'](path.join(__dirname, file));
          console.log('here');
          // NOTE: you have to change from the original property notation to
          // index notation or tsc will complain about undefined property.
          db[model['name']] = model;
      });
  </code></pre>
  
  <p>I then have models structured like this <code>/models/user.ts</code>:</p>
  
  <pre><code>export default function defineUser(sequelize: Sequelize.Sequelize, DataTypes) {
    var User = sequelize.define&lt;UserInstance, UserAttributes&gt;('User', {
      email: {
        type: Sequelize.STRING,
        unique: true,
        validate: { isEmail: true }
      },
      password: Sequelize.STRING
    });
    return User;
  };
  </code></pre>
  
  <p>However, I cannot then import a model from one file to another unable to do something like:</p>
  
  <pre><code>import * as User from './user'
  // ... 
  // definition of job model
  // ...
  Job.hasOne(User);
  </code></pre>
  
  <p>As I get <code>Argument of type 'typeof "~/models/job-response"' is not assignable to parameter of type 'Model&lt;any, any&gt;'.</code> and then:</p>
  
  <blockquote>
    <p>~/node_modules\sequelize\lib\associations\mixin.js:95
    [1]       throw new Error(this.name + '.' + Utils.lowercaseFirst(Type.toString()) + ' called with something that\'s not an instance of Sequelize.Model');
    [1]       ^
    [1]
    [1] Error: Job.function (srcModel, targetModel, options) {
    [1]   Association.call(this);
    [1]
    [1] } called with something that's not an instance of Sequelize.Model
    [1]     at Model.hasOne (~\node_modules\sequelize\lib\associations\mixin.js:95:13)</p>
  </blockquote>
  
  <p>How should I access a model instance such that it can be passed to the <code>hasMany()</code> or <code>hasOne()</code> functions.</p>