1

I'm getting this error Property 'pwd' does not exist on type 'Model<any, any>' even when the model is defined as Model<Attribs, OptionalAttribs>, below give is the snippet

model def

import {Optional, ModelAttributes , STRING, UUID, DataTypes } from 'sequelize'
import { Table, Model } from 'sequelize-typescript'

export type Attribs = Required<IAppUser>
export type OptionalAttribs = Optional<IAppUser, 'id'>

@Table
class AppUser extends Model<Attribs, OptionalAttribs> {
    public pwd!: string
}

export const AppUserAttributes = {
    id: {
        type: UUID,
        defaultValue: DataTypes.UUIDV4,
        allowNull: false
    }
    pwd: {
        type: STRING,
        allowNull: false
    }
}

import { Sequelize } from 'sequelize-typescript'
sequelize.addModels([AppUser, Algo])

AppUser.init(AppUserAttributes, {sequelize})
AppUser.sync({ force: true })

usage

    const page = req.params.page ? req.params.page : 1;
    const limit = req.params.limit ? req.params.limit : 10;
   const appUsers = await AppUser.findAll({
        limit: limit,
        offset: (page - 1) * limit,
        order: [['id', 'DESC']],
    });
    appUsers?.forEach((appUser) => {
        console.log(appUser)
        appUser.pwd = '******'
    })

package.json

"sequelize": "^6.12.2",
"sequelize-typescript": "^2.1.1",
    ```
its not able to identify appUser as type of Model<Attribs, OptionalAttribs>  rather it takes as Model<any,any>
any pointers why?
the code is @ https://github.com/arunsoman/mintit
user3171954
  • 181
  • 1
  • 1
  • 4
  • What is displayed by the console.log(appUser) ? Can it come from the '!' in the model ? Personnally I have used '?' when declaring variable but not '!'. What happens if you remove '!' from your variable declaration ? – Valentin Roche Jan 17 '22 at 12:16

0 Answers0