AI-generated code often comes riddled with errors, especially TypeScript errors. Trying to fix these one by one with in-editor AI tools (like Cursor's "Fix with AI") can be slow, frustrating, and sometimes even introduce new problems. The fixes can be too localized, missing the bigger picture.
This lesson demonstrates a more efficient workflow: leveraging the power of reasoning models (like those found in AI Studio or advanced ChatGPT models) to fix errors in bulk.
Here's the process:
Cmd/Ctrl + Shift + P, then type "problems".)yargs), provide even more context to the AI:
@ feature to add specific files or documentation to the context.npm test or whichever testing command you're using for this project.Why this works:
This lesson teaches you a practical, powerful technique to tame AI-generated code and get it working quickly, even when it arrives full of errors. By combining the strengths of reasoning models and in-editor AI, you'll become a more efficient and confident developer.
[00:00] When you get some AI generated code and you see a lot of red on your sidebar and it looks like there's a ton of TypeScript issues or whatever kind of issues, if you hit Command-Shift-P and type in problems, you can focus on the list of all the problems in the file. So this has a whole bunch of TypeScript issues. Now in a lot of cases you can right-click on these and say fix with AI, fix with AI, and go one by one and attempt to let cursor fix them as kind of standalone issues. My personal workflow is to grab the entire file to drop it into the smartest AI you have access to. I use O3 MiniHi all the time so I'll paste in this file and then just as a habit I always wrap sections with XML tags.
[00:43] I'll swap back over to cursor, hit command-a, select all of these and copy and swap back and paste and then end the problem section and then just say please fix all of these problems and write out the entire file with the problems fixed. You can say that however you want. Then we'll submit this and let it go to work so that essentially everything is done in a single pass. So this actually took quite a while, two minutes, but from my experience I have a lot more trust in reasoning models than I do in one-shot fixes inside of Cursor. So we can go ahead and take this entire file, It's almost done actually generating the text of it.
[01:17] So we can go ahead and copy the result, click copy, switch back, select all, paste, and you'll see we have a few more errors. We'll just select all, copy, swap back, paste it in, and since this looks like they're all just on like line 68, 498, 541. We'll just say there are a few errors remaining, just give me the minimal code snippets that I can copy paste in to fix these. And then once this is done I'll copy the result, swap back over. I'm actually going to ask Composer to fix this, so I'll drop that in.
[01:46] Please apply the fixes we made above, hit enter here, and then just let it go to work. Again with the end goal of just me being as lazy as possible. We'll accept the changes. We only have a couple left. I'll just try right-clicking and fix with AI on these.
[01:59] We'll accept, fix with AI. Looks like that's still not fixed. We'll try it again. I doubt we'll have to go to a reasoning model for this, but that definitely introduced a lot of issues. Let's skip this one for a second and fix this with AI.
[02:15] Except Let's try copying both of these in, creating a new session, and see if Claude can do this. Please fix these issues. And because this seems to be YARG-specific, I'm going to grab in the YARG's URL from npm and paste this in. And there's even a YARGS docs and I'll just go ahead and add that to docs while I'm here. So I'll say docs add new, paste the link, hit enter, call it YARGS, confirm, and then now we have yargs or yargs or however you say it and maybe now this will help it out.
[02:52] So let this do its work. Let's go ahead and accept. Let's add this line to Composer and right-click copy the message, paste it in, please fix. Hopefully this should take care of it. We'll hit accept here and now the only thing to do is to pray that our tests still pass.
[03:09] And it looks like I do have one test that failed around the text used to help the user when they look to see how to use it. So we can go ahead and select all of this and say add to composer. You broke this test, please fix it. And then it's just the usage string. Looks up the changes and then I imagine we're good to go now.
[03:27] So with everything passing at this point I would still take this entire file, drop it in a reasoning model, see what sort of types it could extract. This file is definitely getting to the size where I need to start pulling out functions, pulling out types, and making this more than just a single file utility. But for now I cleared out all of the TypeScript issues without ever really having to think about TypeScript.