K
K
komigor2021-07-10 22:09:07
typescript
komigor, 2021-07-10 22:09:07

How to save normal information in the database?

Here I have created a data model.

import { Model, DataTypes } from 'sequelize';
import db from '../db';

interface ImgAttributes {
  id: number;
  fileSizeBytes: number;
  url: string;
}

class Img extends Model <ImgAttributes> {}

Img.init({
  id: {
    type: DataTypes.INTEGER.UNSIGNED,
    autoIncrement: true,
    primaryKey: true,
  },
  fileSizeBytes: {
    type: DataTypes.STRING(128),
    allowNull: false,
  },
  url: {
    type: DataTypes.STRING(128),
    allowNull: false,
  },
},
{
  sequelize: db,
  tableName: 'images',
});

export default Img;

And I'm trying to save the values ​​\u200b\u200bto there in another place, but it gives me
await img.create({ 2, "фыаацаа"});

/home/ihor/Test Task by Komah Ihor/node_modules/ts-node/src/index.ts:587
    return new TSError(diagnosticText, diagnosticCodes);
           ^
TSError: ⨯ Unable to compile TypeScript:
src/app.ts:25:20 - error TS2345: Argument of type '{}' is not assignable to parameter of type 'ImgAttributes'.
  Type '{}' is missing the following properties from type 'ImgAttributes': id, fileSizeBytes, url

25   await img.create({});
                      ~~

What to do? What am I doing wrong? I'm a complete zero in TS if the deadlines are burning

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aetae, 2021-07-11
@Aetae

It would seem, what does typescript have to do with it?
What is this: bullshit? An array in javascript in square brackets is specified, while an object requires specific keys. { 2, "фыаацаа"}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question