sequelize / sequelize-typescript

Decorators and some other features for sequelize

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

'id' is defined as a property in class 'Model<any, any>', but is overridden here in 'Person' as an accessor.ts (2611)

marshalltower opened this issue · comments

Issue

When using a primary key other than the default 'id', typescript will error when using a getter for remapping the new primary key to the default field. Happens in Typescript 3 as a non-blocking error, but is enforced in Typescript 4 preventing upgrading.

Versions

  • sequelize: 5.22.5
  • sequelize-typescript: 1.1.0
  • typescript: 4.9.5

Issue type

  • bug report
  • feature request

Actual behavior

Expected behavior

Steps to reproduce

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

@Table
class Person extends Model {
  @Column
  Id: string;

  @Column
  Name: string;

  get id(): string {
    return this.getDataValue('Id');
  }
  get name(): string {
    return this.getDataValue('Name');
  }
}

Related code

export declare abstract class Model<T = any, T2 = any> extends OriginModel<T, T2> {
    id?: number | any;
    createdAt?: Date | any;
    updatedAt?: Date | any;
    deletedAt?: Date | any;
    version?: number | any;
    static isInitialized: boolean;
    static init(attributes: ModelAttributes, options: InitOptions): void;
    constructor(values?: object, options?: BuildOptions);
    /**
     * Adds relation between specified instances and source instance
     */
    $add<R extends Model<R>>(propertyKey: string, instances: R | R[] | string[] | string | number[] | number, options?: AssociationActionOptions): Promise<unknown>;
    /**
     * Sets relation between specified instances and source instance
     * (replaces old relations)
     */
    $set<R extends Model<R>>(propertyKey: keyof this, instances: R | R[] | string[] | string | number[] | number, options?: AssociationActionOptions): Promise<unknown>;
    /**
     * Returns related instance (specified by propertyKey) of source instance
     */
    $get<K extends keyof this>(propertyKey: K, options?: AssociationGetOptions): Promise<$GetType<this[K]>>;
    /**
     * Counts related instances (specified by propertyKey) of source instance
     */
    $count<R extends Model<R>>(propertyKey: string, options?: AssociationCountOptions): Promise<number>;
    /**
     * Creates instances and relate them to source instance
     */
    $create<R extends Model<R>>(propertyKey: string, values: any, options?: AssociationCreateOptions): Promise<R>;
    /**
     * Checks if specified instances is related to source instance
     */
    $has<R extends Model<R>>(propertyKey: string, instances: R | R[] | string[] | string | number[] | number, options?: AssociationGetOptions): Promise<boolean>;
    /**
     * Removes specified instances from source instance
     */
    $remove<R extends Model<R>>(propertyKey: string, instances: R | R[] | string[] | string | number[] | number, options?: any): Promise<any>;
    reload(options?: FindOptions): Promise<this>;
}

Also applies for situations like

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

@Table
class Person extends Model {
  @Column
  CreatedAt: string;

  get createdAt(): string {
    return this.getDataValue('CreatedAt');
  }
}