Sequelize-typescript: How to get inferred types?

Created on 22 Mar 2019  路  6Comments  路  Source: RobinBuschmann/sequelize-typescript

I feel like I'm missing something here, every function call I do seems to return "any" types in vscode rather than a Promise.

e.g. "then" and "post" in this example are both of type "any":

const post = await Post.findOne();

Post.findOne().then(post => {

});

Post class:

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

@Table({
    tableName: "post",
    timestamps: false
})
export class Post extends Model<Post> {
    @Column({ primaryKey: true })
    id: number;

    @Column
    game_title: string;

    @Column
    overview: string;

    @Column
    release_date: string;

    @Column
    platform: number;

    @Column
    players: number;
}

export default Post;

tsconfig:

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "commonjs",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,  /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
    "esModuleInterop": true,                   /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */

    "target": "es6",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "es2016",
      "es2015",
      "es6",
      "dom",
    ]
  },
  "include": [
    "main.ts",
    "src/**/*"
  ],
  "exclude": [
    "node_modules"
  ]
}

Most helpful comment

@ian-callaghan This is because the bluebird typings (@types/bluebird) are missing like documented here: http://docs.sequelizejs.com/manual/typescript.html

I will also add this to the sequelize-typescripts docs.

Thanks for bringing this up 馃憤

All 6 comments

@ian-callaghan Your setup looks good to me - it should work. Can you provide an example repo which reproduces the issue?

@ian-callaghan Your setup looks good to me - it should work. Can you provide an example repo which reproduces the issue?

Here's a barebones example that has the issue in vs code: https://github.com/ian-callaghan/sequelize-issue

@ian-callaghan This is because the bluebird typings (@types/bluebird) are missing like documented here: http://docs.sequelizejs.com/manual/typescript.html

I will also add this to the sequelize-typescripts docs.

Thanks for bringing this up 馃憤

@ian-callaghan This is because the bluebird typings (@types/bluebird) are missing like documented here: http://docs.sequelizejs.com/manual/typescript.html

I will also add this to the sequelize-typescripts docs.

Thanks for bringing this up

Ahhh don't think I even notice that doc page :). Thanks is it worth putting the bluebird typings as a dependency in sequelize-typescripts package.json ass well so people don't have to manually install it?

Edit: I see that the typings are already in the package, is this expected behaviour or a seperate bug with npm/vs code?

It caused a lot of issues in the past see #165. So at most as a peerDependency with a loose requirement.

Edit: I see that the typings are already in the package, is this expected behaviour or a seperate bug with npm/vs code?

Only under devDependencies

Closing this since typings are now listed under peerDependencies since [email protected]:

{
    "@types/bluebird": "*",
    "@types/node": "*",
    "@types/validator": "*",
    "reflect-metadata": "*",
    "sequelize": "^5.1.0"
  }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

CampaUTN picture CampaUTN  路  4Comments

fareshan picture fareshan  路  4Comments

libvirtadept picture libvirtadept  路  4Comments

fareshan picture fareshan  路  3Comments

JustGreg picture JustGreg  路  4Comments