2

I'm using postgres database ORM sequelize and I'm using typescript as a backend script for in express nodeJs.

First question: Is there a way to create a model directly to.ts ?

Second question: While trying to migrate the db I'm getting this message:

"File: 20180424170257-create-todo.ts does not match pattern: /.js$/"

Where can I specify the compiled migration ?

Thanks.

Guy Avraham
  • 3,482
  • 3
  • 38
  • 50

1 Answers1

0

Sequelize doesn't come with it's own type definitions, so in order to add them you need to install them from DefinitelyTyped

npm install @types/sequelize

You can create a model directly with those type definitions in place. For examples you can check the tests of sequelize.d.ts

It looks like

interface TaskAttributes {
    revision? : number;
    name? : string;
}

// For your instance methods
interface TaskInstance extends Sequelize.Instance<TaskAttributes> {
    upRevision(): void { ... };
}

const GTask = s.define<TaskInstance, TaskAttributes>( 'task', { 
    revision : Sequelize.INTEGER, 
    name : Sequelize.STRING 
} );

As for your second question. Umzug uses plain JS files for your migrations, so you will have to either compile them to JS files and then use them ( in a build step, before you run the migrations ), or just write them in JavaScript and not TypeScript.

drinchev
  • 19,201
  • 4
  • 67
  • 93