In my application, I am working with PostgreSQL, Sequelize, Sequelize-TypeScript, and TypeScript. I have a need for a table called Role
where each role has multiple permissions of type integer. I'm following the guidelines provided in the sequelize-typescript documentation. Here is how I have defined it:
@Table
export default class Role extends Model {
@HasMany(() => number)
declare permissions: Number[]
}
For another model I use @HasMany(() => MyType)
and MyType[]
, which works perfectly fine.
The issue arises when trying to implement the above code snippet as it throws the error:
'number' only refers to a type, but is being used as a value here
.
Even changing @HasMany(() => Number)
to capitalize "N" results in a different error:
No overload matches this call.
Overload 1 of 2, '(associatedClassGetter: ModelClassGetter<any, unknown>, foreignKey?: string | undefined): Function', gave the following error.
Type 'NumberConstructor' is not assignable to type 'ModelType<any, unknown>'.
Type 'Number' is missing the following properties from type 'Model<unknown, any>': $add, $set, $get, $count, and 32 more.
Overload 2 of 2, '(associatedClassGetter: ModelClassGetter<any, unknown>, options?: HasManyOptions | undefined): Function', gave the following error.
Type 'NumberConstructor' is not assignable to type 'ModelType<any, unknown>'.
I'm unsure of what I might be missing. Is it incorrect to use arrays of primitive types in this scenario?
PS: Changing declare permissions: Number[]
to declare permissions: number[]
doesn't seem to make any difference.