sequelize-typescript icon indicating copy to clipboard operation
sequelize-typescript copied to clipboard

Sequelize types being imported inside sequelize-typescript types are inferred to any

Open swordman1205 opened this issue 6 years ago • 4 comments

Versions

  • sequelize: 5.21.11
  • sequelize-typescript: 1.1.0
  • typescript: 3.9.3

I'm submitting a ...

[x] bug report [ ] feature request

Actual behavior:

I am creating sequelize models as a shared lib for microservice-like backend architecture so the models can be imported over multiple repos. Our backend is coded with Typescript so I used sequelize-typescript to support TS in the shared model repo. Everything seems working well, but actually every sequelize types being used inside sequelize-typescript types are inferred to any in my microservice repos.

Expected behavior:

I would like to get all the shared functions and variables output with accurate sequelize types. I spent a couple days on this issue for investigation. Look https://github.com/microsoft/TypeScript/issues/23918

Steps to reproduce:

Related code:

My shared model example:

import { Model, Table } from 'sequelize-typescript';

@Table({
  timestamps: true,
  underscored: true,
  tableName: 'members'
})
export class Members extends Model {
  // Columns
  ...
}

How to use the model above in my backend repos:

import { Members } from '@xxx/models';
...
const member = await Members.findOne({
  where: { xx: xx }
}); // member is inferred to any. findOne function should be inferred to Promise<Member>.

Thank you for your help in advance @RobinBuschmann

swordman1205 avatar Jun 11 '20 03:06 swordman1205

same problem

zcong1993 avatar Jul 02 '20 08:07 zcong1993

Solution: https://github.com/RobinBuschmann/sequelize-typescript/issues/575#issuecomment-478235968 I've just tested it and works fine (had the same problem). Issue can be closed.

ertwroc avatar Aug 03 '20 09:08 ertwroc

I'm still having this exact issue, even after installing Bluebird types.

LucasLundJensen avatar Nov 23 '20 09:11 LucasLundJensen

For anyone who stumbles into this one, an explanation is given here: #858

LucasLundJensen avatar Dec 03 '20 21:12 LucasLundJensen