Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to set INTEGER length for column #1492

Closed
1 of 2 tasks
ChristianVaughn opened this issue Oct 26, 2022 · 2 comments
Closed
1 of 2 tasks

Not able to set INTEGER length for column #1492

ChristianVaughn opened this issue Oct 26, 2022 · 2 comments

Comments

@ChristianVaughn
Copy link

ChristianVaughn commented Oct 26, 2022

Issue

I am porting my models from normal sequelize to sequelize-typescript. I am trying to define a column on my model and give it a type of INTEGER(N).UNSIGNED to match what is in my mysql database. Some examples of my code are(names of models redacted):

@Table({modelName: 'modelName', tableName: 'modelNames'})
export class ModelName extends Model<ModelName> {

  @PrimaryKey
  @AutoIncrement
  @Column(DataType.INTEGER.UNSIGNED)
  id: number

  @Column(DataType.INTEGER(2).UNSIGNED)
  buildMajor: number

  @Column(DataType.INTEGER(3).UNSIGNED)
  buildMinor: number

Versions

  • sequelize: 5.22.5
  • sequelize-typescript: 1.1.0
  • typescript: 3.7.3

Issue type

  • bug report
  • feature request

Actual behavior

On doing this both when trying to build for release, and in the VsCode intelisense i get an error such as

src/models/ModelNameHere.ts:71:28 - error TS2769: No overload matches this call.
  Overload 1 of 2, '(options?: NumberDataTypeOptions): IntegerDataType', gave the following error.
    Type '3' has no properties in common with type 'NumberDataTypeOptions'.
  Overload 2 of 2, '(options?: NumberDataTypeOptions): NumberDataType', gave the following error.
    Type '3' has no properties in common with type 'NumberDataTypeOptions'.

71   @Column(DataType.INTEGER(3).UNSIGNED)

Expected behavior

According to documentation You should be able to define a length of the integer via (N) because sequelize typescript uses the same DataType as sequelize.

Steps to reproduce

Create a model with a table and some columns. Try to make the datatype of a column DataType.INTEGER(2) or DataType.INTEGER(2).UNSIGNED where 2 can be replaced with any number that's allowed for an int length in mysql

@maxclaus
Copy link

maxclaus commented Nov 8, 2022

FYI, as a temporary solution, I worked around it this way:

import { DataTypes, NumberDataTypeOptions } from 'sequelize';

DataType.INTEGER(3 as NumberDataTypeOptions)

@Santiagomrn
Copy link

You can leverage the NumbreDataTypeOptions interface by using them

import {DataType} from "sequelize-typescript"
DataType.INTEGER({length:2}).UNSIGNED

But if you really want use DataType.INTEGER(2) you can create a declaration.d.ts file in the root folder of your project and paste this

import { DataTypeAbstract,NumberDataType, NumberDataTypeOptions} from "sequelize";

declare module "sequelize"{
    interface NumberDataTypeConstructor extends DataTypeAbstract {
        options: NumberDataTypeOptions;
        UNSIGNED: this;
        ZEROFILL: this;
        new (options?: NumberDataTypeOptions): NumberDataType;
        (options?: NumberDataTypeOptions): NumberDataType;
        new (length?: number): NumberDataType;
        (length?: number): NumberDataType;
        validate(value: unknown): boolean;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants