Skip to content
Advertisement

How to import a js Module as any. (Without any declaration file (d.ts))

So I want to import a js module in my ts app.

Is there a way to do this without making a d.ts file or if not how to declare it as any in the d.ts file?

I am currently just ignoring this error with //@ts-ignore.

Thanks!

Advertisement

Answer

There are two cases here:

  • You are using ESM modules, and only have import(...) available
const module = (await import('module')) as any;
  • You aren’t using ESM modules, therefore you have access to require(...)
const module = require('module') as any;
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement