Demo, all content is generated
Question

Cursor 'fixes' TypeScript errors by adding any everywhere

Solved · 301 views · asked by dan_the_intern · edited

My team lead reviewed my PR and there are like 30 as any and : any in it. Cursor adds them whenever there's a type error. How do I stop it doing that? I'm at my first internship and a bit embarrassed.

What I’ve tried

Added 'don't use any' to my prompt, works for that prompt, forgets the next time.

Comment
Is it strict mode already? Check "strict": true in tsconfig. mei_lin · edited
It is, yes. dan_the_intern · edited

3 answers

Marked as helpful by the asker
dev_ana · edited

Make it impossible instead of asking nicely:

// eslint.config.mjs
rules: {
  '@typescript-eslint/no-explicit-any': 'error',
}

Then a rule in .cursor/rules with alwaysApply: true: "Never use any or as any. If a type is unclear, stop and ask. Run npm run lint after changes."

Now the agent sees the lint error itself and has to find the real type. When it truly can't, unknown plus a check is the honest fallback.

And don't be embarrassed; your lead caught it in review, that's what review is for.

Comment
Lint rule + always-apply rule works. Lead was happy with the follow-up PR. dan_the_intern · edited
mei_lin · edited

Also, many of those anys are usually one missing type at the source (an untyped fetch response). Type that once and 20 errors disappear.

Comment
aiko_n · edited

If the untyped thing is an API response, validate it with zod and infer the type from the schema (z.infer<typeof Schema>). One schema, real types everywhere, and bad data fails loudly instead of hiding behind any.

Comment