DEV Community

Cover image for Why GitHub Copilot Defaults to 'any' in React TypeScript Projects
Avery
Avery

Posted on

Why GitHub Copilot Defaults to 'any' in React TypeScript Projects

There is a pattern that shows up constantly in React TypeScript projects where GitHub Copilot was involved.

It looks like this:

const [data, setData] = useState<any>(null)

const handleResponse = (response: any) => {
  setData(response.data)
}
Enter fullscreen mode Exit fullscreen mode

TypeScript is installed. The project is set up correctly. And Copilot still reaches for any — every single time.

Why this happens

Copilot is not trying to write bad TypeScript. It is taking the path of least resistance.

any works. It compiles. It does not throw errors. And without explicit constraints telling Copilot what the actual types are, it defaults to the safest assumption it can make — which is no assumption at all.

The result is TypeScript that looks correct but provides zero protection. You have all the overhead of a typed language with none of the benefits.

What any actually costs you

TypeScript exists to catch errors before they reach production. The moment you use any, that protection disappears for that value — and everything that touches it.

A component that receives any as a prop passes any down the tree. A function that returns any spreads uncertainty through the entire codebase. One any becomes ten. Ten becomes a codebase where TypeScript is installed but not actually working.

And the worst part is that it fails silently. No warnings. No errors. Just runtime surprises that TypeScript was supposed to prevent.

What changes when you give Copilot explicit types

When you define your domain types clearly and tell Copilot to use them, the output changes completely.

Instead of any, Copilot reaches for the types you have already defined. Props are typed correctly. API responses are mapped to real interfaces. State has a shape.

The key is that Copilot needs the context. It cannot invent your domain types. You have to give them.

The deeper problem

TypeScript any is just one symptom of a bigger issue.

GitHub Copilot generates code based on what it can see. If your types are vague, your constraints are missing, or your project structure gives it nothing to work with — it improvises.

And improvised TypeScript in a React project is TypeScript in name only.

Want to find where your React project is missing structure?

I built a free 20 point checklist that helps you identify exactly this. Structural and typing weaknesses that make AI output unpredictable and your codebase fragile.

No guessing. No endless follow up prompts. Just a clear picture of what to fix before you prompt again.

👉 Get the React AI Debug Checklist free

And if you want the full system — rules across architecture, typing, state, accessibility, and more:

👉 Avery Code React AI Engineering System

Top comments (0)