DEV Community

csm for Necoz

Posted on Edited on

How to Crash tsc

Unchecked response files cause infinite loops

If you are a TypeScript developer and like the language a lot, but don't like the compiler errors, then I got a secret spell for you.
The spell which will confuse the compiler to crash πŸ˜„

Are you familiar with Response files?

Yeah, this one! I know, we rarely use it.
When we have a lot of options to provide to the compiler, we put them in a file and give it to the compiler like this:

tsc @hello.txt
Enter fullscreen mode Exit fullscreen mode

Then, the compiler reads the options from that file and runs them as if they were provided on the command-line.

You can provide as many response files as you want.

So, what is the spell?

Here is the recipe:

  • Create two files: 1.txt and 2.txt.
  • Fill them with this:

1.txt:

@2.txt
Enter fullscreen mode Exit fullscreen mode

2.txt

@1.txt
Enter fullscreen mode Exit fullscreen mode
  • Run the spell, I mean give the file to tsc:
tsc @1.txt
Enter fullscreen mode Exit fullscreen mode

(Full screen the terminal before running!)

Wait for it, wait for it, then, after roughly 20 seconds, boom!

What happened?

Simple, the compiler read the 1.txt file, it contained an option, that is another response file 2.txt.
So, it ran the option as regular option, so opened the 2.txt file. And, since 2.txt file has 1.txt file as content, it became a loop.
So it keeps opening the two files forever!

Technically, its called Circular reference.
Mostly, its a rare case, but it should be handled by the compiler.
If you are a TypeScipt developer, you can make a PR for this πŸ˜‰

Top comments (9)

Collapse
 
nyaomaru profile image
nyaomaru Necoz • • Edited

Haha, I love this! 😹

Circular dependencies can be such a headache in real-world projects too, especially with barrel exports! Thankfully, I don't run into them much these days when coding with AI. πŸ™Œ

I couldn't resist trying your little spell, and guess what? It worked! πŸ’₯

I managed to reproduce the crash with TypeScript 7.0.2! πŸ’š

Just one tiny thing I noticed! I think the example in the article might be missing the @ prefix in both files.

Here's what worked for me πŸ‘‡

1.txt: @2.txt

2.txt: @1.txt

Without the @, TypeScript treats them as regular source files and reports TS6054 instead.

Might be worth a quick update so everyone can enjoy the magic too! πŸͺ„πŸ˜Έ

Thanks for sharing this fun experiment! I had a good laugh! πŸ’š

Collapse
 
csm18 profile image
csm Necoz •

Oh, I forgot the @.
Thanks for trying it.
I will update it in the article πŸ˜ΈπŸ‘πŸ»

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

Two files pointing at each other and tsc loops for 20 seconds before it falls over. Response files are just options in a file, so nothing stops one from naming the other, and a circular reference check would end it.

Collapse
 
jaypateldev profile image
Jay Patel •

Interesting find! It's surprising how a simple circular reference in TypeScript response files can cause the compiler to get stuck in an endless loop. A good reminder that even small configuration details can have unexpected consequences. Great experiment! πŸ˜„

Collapse
 
technogamerz profile image
π“π‘πž π‹πšπ³π² 𝐆𝐒𝐫π₯ Necoz • • Edited

Bahut achha article hai :D

Collapse
 
hemapriya_kanagala profile image
Hemapriya Kanagala Necoz • • Edited

I had no idea you could do this with response files! That's a pretty interesting way to crash the compiler πŸ˜„

P.S. Definitely not trying this on my actual projects πŸ˜‚

Collapse
 
effessdev profile image
EffessDev Necoz •

πŸ™€ Coooool!!!

Collapse
 
effessdev profile image
EffessDev Necoz •

Oh, this was you, @csm18! I thought it was @nyaomaru when I saw Necoz, but I was thinking why @nyaomaru is writing posts like this. Only you can write posts like these πŸ‘πŸ‘πŸ‘

Collapse
 
nyaomaru profile image
nyaomaru Necoz •

Great article! 😸