Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only import TypeScript types, not the whole module

I have a project that already includes the required JavaScript files. However, I am trying to move some code into TS and take advantage of it. There's a library that I use (sweetalert2) that has been installed and is in node_modules (though not actually used from that location).

All I want to do is somehow include it in my TS files so that I get the Intellisense and type checks. Not actually import the code. If I import the code it does a whole lot of stuff that I don't need or want.

I think I've tried every variation of tsconfig and references and I can't get it to work. There must be a way!

Is there a way to just just reference the types so that you can take advantage in TypeScript and it doesn't complain?

like image 313
Tony Basallo Avatar asked Sep 02 '25 06:09

Tony Basallo


1 Answers

You can use import type() to import only types.

like image 122
Rubydesic Avatar answered Sep 04 '25 23:09

Rubydesic