I am currently in the process of upgrading dependencies of a project but I am getting this error a bunch of times for different service functions:
src/data/data.service.ts:59:39 - error TS2345: Argument of type 'DataInput' is not assignable to parameter of type 'Optional<any, string>'.
Type 'DataInput' is not assignable to type 'Omit<any, string>'.
Index signature for type 'number' is missing in type 'DataInput'.
59 return this.dataRecordModel.create(data, options);
It’s been nearly over a year since I last touched this codebase so trying to determine what the real cause is for this issue. Feels like I’m chasing my tail a little bit as I can’t seem to find the culprit:
Service code:
import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/sequelize';
import { DataInput } from './dto/data-input.dto';
import { DataRecordDTO } from './dto/data-record.dto';
import { DataRecordModel } from './models/data-record.model';
import { CreateOptions } from 'sequelize';
@Injectable()
export class DataService {
constructor(
@InjectModel(DataRecordModel)
private readonly dataRecordModel: typeof DataRecordModel,
) {}
async create(
data: DataInput,
options: CreateOptions = {},
): Promise<DataRecordDTO> {
return this.dataRecordModel.create(data, options);
}
}
Model:
import { Column, Model, Table, DataType, Index } from 'sequelize-typescript';
import {
AgeCategory,
GenderCategory,
EthnicityCategory,
DisabilityCategory,
EducationCategory,
} from '../types/Categories.enum';
@Table({
timestamps: false,
})
export class DataRecord extends Model {
@Index
@Column({ primaryKey: true, autoIncrement: true })
id: number;
@Column({
type: DataType.ENUM(...Object.values(AgeCategory)),
allowNull: false,
})
age: AgeCategory;
@Column({
type: DataType.ENUM(...Object.values(GenderCategory)),
allowNull: false,
})
gender: GenderCategory;
@Column({
type: DataType.ENUM(...Object.values(DisabilityCategory)),
allowNull: false,
})
disability: DisabilityCategory;
@Column({
type: DataType.ENUM(...Object.values(EthnicityCategory)),
allowNull: false,
})
ethnicity: EthnicityCategory;
@Column({
type: DataType.ENUM(...Object.values(EducationCategory)),
allowNull: false,
})
highestEducation: EducationCategory;
}
The input type:
import { InputType, Field } from '@nestjs/graphql';
@InputType()
export class DataInput {
@Field(() => AgeCategory, { description: 'Age range provided' })
age: AgeCategory;
@Field(() => GenderCategory, { description: 'Gender provided' })
gender: GenderCategory;
@Field(() => EthnicityCategory, { description: 'Ethnicity provided' })
ethnicity: EthnicityCategory;
@Field(() => DisabilityCategory, { description: 'Disability provided' })
disability: DisabilityCategory;
@Field(() => EducationCategory, {
description: 'Highest educational attainment provided',
})
highestEducation: EducationCategory;
}
The DataInput type has always been used this way and has worked fine before. What changes might have caused this issue, and how can I resolve it without resorting to any type casting?
These are my dependencies in my package.json
:
"dependencies": {
"@nestjs/cli": "^7.6.0",
"@nestjs/common": "^7.6.18",
"@nestjs/config": "^0.6.3",
"@nestjs/core": "^7.6.18",
"@nestjs/graphql": "^7.11.0",
"@nestjs/jwt": "^7.2.0",
"@nestjs/passport": "^7.1.6",
"@nestjs/platform-express": "^7.6.18",
"@nestjs/schedule": "^1.1.0",
"@nestjs/sequelize": "^0.2.0",
"@types/geojson": "^7946.0.14",
"@types/uuid": "^9.0.8",
"apollo-server-express": "^2.23.0",
"aws-sdk": "^2.1624.0",
"bcrypt": "^5.1.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"crypto": "^1.0.1",
"dataloader-sequelize": "^2.3.3",
"graphql": "^15.8.0",
"graphql-tools": "^7.0.4",
"graphql-type-json": "^0.3.2",
"handlebars": "^4.7.8",
"node-fetch": "^2.7.0",
"parse-database-url": "^0.3.0",
"passport": "^0.7.0",
"passport-jwt": "^4.0.1",
"passport-local": "^1.0.0",
"pg": "^8.11.5",
"pg-hstore": "^2.3.4",
"postmark": "^2.9.5",
"reflect-metadata": "^0.2.2",
"rimraf": "^3.0.2",
"rxjs": "^6.6.7",
"sequelize": "^6.37.3",
"sequelize-typescript": "^2.1.6",
"uuid": "^8.3.2"
},
"devDependencies": {
"@nestjs/schematics": "^7.3.1",
"@nestjs/testing": "^7.6.18",
"@types/bcrypt": "^3.0.1",
"@types/express": "^4.17.21",
"@types/jest": "^26.0.24",
"@types/node": "^14.18.63",
"@types/passport-jwt": "^3.0.13",
"@types/passport-local": "^1.0.38",
"@types/sequelize": "^4.28.20",
"@types/supertest": "^2.0.16",
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"cross-env": "^7.0.3",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-prettier": "^3.4.1",
"jest": "^26.6.3",
"prettier": "^2.8.8",
"supertest": "^6.3.4",
"ts-jest": "^26.5.6",
"ts-loader": "^8.4.0",
"ts-node": "^9.1.1",
"tsconfig-paths": "^3.15.0",
"typescript": "^4.9.5"
},
"engines": {
"node": "14.15.1"
}