Я создал конфигурацию для ts проекта через sequlize cli. Но почему-то models/models.js файл не подключается вот код app.ts
import db from './models';
Вот ошибка:
/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:3:16 - error TS7016: Could not find a declaration file for module './models'. '/home/ihor/Test Task by Komah Ihor/src/models/index.js' implicitly has an 'any' type.
3 import db from './models';
~~~~~~~~~~
at createTSError (/home/ihor/Test Task by Komah Ihor/node_modules/ts-node/src/index.ts:587:12)
at reportTSError (/home/ihor/Test Task by Komah Ihor/node_modules/ts-node/src/index.ts:591:19)
at getOutput (/home/ihor/Test Task by Komah Ihor/node_modules/ts-node/src/index.ts:921:36)
at Object.compile (/home/ihor/Test Task by Komah Ihor/node_modules/ts-node/src/index.ts:1189:32)
at Module.m._compile (/home/ihor/Test Task by Komah Ihor/node_modules/ts-node/src/index.ts:1295:42)
at Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Object.require.extensions.<computed> [as .ts] (/home/ihor/Test Task by Komah Ihor/node_modules/ts-node/src/index.ts:1298:12)
at Module.load (internal/modules/cjs/loader.js:933:32)
at Function.Module._load (internal/modules/cjs/loader.js:774:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
[nodemon] app crashed - waiting for file changes before starting...
вот config/config
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('dotenv').config();
module.exports = {
development: {
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
host: '127.0.0.1',
dialect: 'postgres',
},
test: {
username: 'root',
password: null,
database: 'database_test',
host: '127.0.0.1',
dialect: 'mysql',
},
production: {
usernam: 'root',
password: null,
database: 'database_production',
host: '127.0.0.1',
dialect: 'mysql',
},
};
вот model/index.js
'use strict';
const fs = require('fs');
const path = require('path');
const Sequelize = require('sequelize');
const basename = path.basename(__filename);
const env = process.env.NODE_ENV || 'development';
const config = require(__dirname + '/../config/config.json')[env];
const db = {};
let sequelize;
if (config.use_env_variable) {
sequelize = new Sequelize(process.env[config.use_env_variable], config);
} else {
sequelize = new Sequelize(config.database, config.username, config.password, config);
}
fs
.readdirSync(__dirname)
.filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.ts');
})
.forEach(file => {
const model = require(path.join(__dirname, file))(sequelize, Sequelize.DataTypes);
db[model.name] = model;
});
Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {
db[modelName].associate(db);
}
});
db.sequelize = sequelize;
db.Sequelize = Sequelize;
module.exports = db;
Что не так?
"compilerOptions": { "allowJs": true }