`await import()` without global execution
Hello there.
This is some code from my
test.ts
:
When I import test.ts
via
the code inside test.ts
will be executed and I get Hello World
to the console. Is it possible that I import only exported code from test.ts
and do not run any of it intrinsically?4 Replies
no, because
test.ts
could do something like this:
^ Instead you should wrap your top-level test.ts code in
if (import.meta.main) {}
assuming that's what you want.Maybe you already considered this, but it seems like a bad idea in general to import things from a test module
Oh, this seems like a misunderstanding 😅
test.ts
is just some random file, has nothing to do with actual tests.
But thanks @Andreu Botella (he/they), that's what I assumed as well…