typescript
type_error
ai_generated
true
error TS2304: Cannot find name 'identifier'
ID: typescript/ts2304-cannot-find-name
90%Fix Rate
92%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 5 | active | — | — | — |
Root Cause
TypeScript can't resolve a name. Missing import, missing type declaration, or wrong tsconfig.
genericWorkarounds
-
95% success Add the missing import or install @types package
npm install -D @types/package-name
Sources: https://www.typescriptlang.org/docs/handbook/2/type-declarations.html
-
85% success Check tsconfig include/exclude paths and module resolution settings
Check tsconfig include/exclude paths and module resolution settings
-
88% success For global types, add a .d.ts file and include it in tsconfig
// Create src/global.d.ts: declare const __DEV__: boolean; declare const API_URL: string; // In tsconfig.json: { "include": ["src/**/*.ts", "src/**/*.d.ts"] }Sources: https://www.typescriptlang.org/docs/handbook/2/type-declarations.html
Dead Ends
Common approaches that don't work:
-
Add // @ts-ignore above the line
85% fail
Disables all type checking for that line, hiding real errors
-
Cast to any
80% fail
Defeats the purpose of TypeScript
Error Chain
Preceded by:
Frequently confused with: