DEV Community

csm for Necoz

Posted on

How to Crash tsc

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 (7)

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
 
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! 😸

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 😂