TypeScript Can I import regular js into a .ts file?

I use webpack and write in es6. I am in the process of integrating typescript into a project. so I need to import the "old" es6 modules into a new .ts file. I keep getting the following error:

let's say i have

const consts = {
  login: '/api/login',
  user: '/api/user',
  register: '/api/register'
};

export default consts;

and I import these constants into a.ts file:

import * as api from '../consts/api.js';

class A implements {
  constructor() {
    console.log(api)
  }
}

export default AuthorizationServiceDIfa;

and I get the following error:

TS2307: Cannot find module '../consts/api.js'.
+4
source share

Source: https://habr.com/ru/post/1650674/


All Articles