TypeScript error TS2304 is reported when an identifier is used but TypeScript cannot find a declaration for it in the current scope. This is the TypeScript equivalent of a ReferenceError and is caught at compile time.
Why it happens
- •A function, variable, or type is used without being imported or declared.
- •A global type (like window, document, or process) is used without the appropriate @types package.
- •A type from a third-party library is used without installing @types for that library.
- •A typo in the identifier name.
Examples
Code that triggers the error
const result = add(2, 3); // 'add' not importedError output
error TS2304: Cannot find name 'add'.
How to fix it
Import the identifier from the correct module. Install the relevant @types package for missing globals. Check for typos in names. Configure your tsconfig.json lib or types array to include the environment globals you need.
Fixed code
import { add } from "./math";
const result = add(2, 3);Related errors
Ready to practice your English at work?
Lingua-e has interactive exercises built around real developer conversations: standups, code reviews, retrospectives, and more. Practice until it comes naturally.
Try Lingua-e for free